A Pennsylvania prosecutor on Wednesday hit back at efforts by lawyers for Bill Cosby to have the criminal charges against Mr. Cosby dismissed, describing their claim that a former district attorney made a promise not to prosecute the entertainer a decade ago as meritless.

“Only a judge may issue an order granting immunity in Pennsylvania,” the prosecutor, Montgomery County District Attorney Kevin R. Steele, said in court papers.

Mr. Cosby’s lawyers had asked the court last week to dismiss the sexual assault charges because, they said the former district attorney, Bruce Castor, had agreed in 2005 not to prosecute the entertainer.

Mr. Castor had decided there was insufficient evidence to charge Mr. Cosby, who had been accused by Andrea Constand, a Temple University staff member, of drugging and molesting her at his Pennsylvania home in 2004. Mr. Castor had hoped, according to an email he wrote that was filed as an exhibit Wednesday, that a non-prosecution agreement would convince Mr. Cosby to testify freely under oath during a subsequent civil case brought by Ms. Constand, and possibly increase her chances of prevailing.