All eyes will be on the testimony of a former prosecutor at a pretrial hearing on sex assault charges against disgraced comedian Bill Cosby Tuesday where a judge has the power to throw out the whole case.

Bruce Castor, the former Montgomery County D.A., is expected to testify Tuesday that current DA Kevin Steele — who campaigned against Castor to victory last year — is not allowed to charge Cosby because of a promise Castor made while in office.

Steele has rejected that argument, countering that "only a judge may issue a grant of immunity, which was not done in 2005 or since."

Cosby is charged with aggravated indecent assault for allegedly sexually abusing former Temple University basketball coach Andrea Constand in 2004 at his Elkins Park mansion. That case is built heavily on Cosby's deposition for Constand's civil suit against him, in which he acknowledged giving her drugs before digitally penetrating her.

Cosby's lawyers say Cosby only gave up his Fifth Amendment right against self-incrimination because of a non-prosecution agreement between Castor and Cosby's former lawyer Walter Phillips, who died last year. Castor has backed up that version of events, which however was never entered into any legal record.

Cosby's lawyers argue in a motion to dismiss charges that "then-District Attorney Bruce Castor promised in 2005 that Mr. Cosby would not be charged in connection with these allegations, in exchange for Mr. Cosby giving testimony in the complainant's civil case against him...  the probable cause affidavit is using the very testimony Mr. Cosby provided in reliance on that agreement against him as a basis for the charges."

As the agreement was off the record, some lawyers say it would not be legally binding.

"A promise by one DA does not bind the successor," New York defense lawyer Frank Hurley said of the agreement.

But Las Vegas defense lawyer Nicholas  Wooldridge said a judge might find a verbal agreement legally binding.

"Cosby could move to have the deposition testimony kept out of his criminal trial, under the theory that the prosecution only got that testimony because of its promise to Cosby," Wooldridge said. "This was the same county and same office, so promises/representations made by the previous DA could be binding on the successor DA."

If they lose on this, Cosby's lawyers are almost certain to appeal the issue to a higher court — and appeals could tie the case up for months, if not years.