Bill Cosby and his lawyers have gone to court to try to get the sexual assault case against him thrown out because of what they say was a binding commitment by a previous district attorney not to prosecute him a decade ago.

Bill Cosby and his lawyers have gone to court to try to get the sexual assault case against him thrown out because of what they say was a binding commitment by a previous district attorney not to prosecute him a decade ago.

The current district attorney has said he has no record of such an agreement.

Cosby, 78, arrived for the hearing in a black SUV, dressed in a tan suit and tie. Two men held his arms for support as he walked up a ramp to the Montgomery County Courthouse, and one carried Cosby's cane. The comedian chatted with his handlers while ignoring reporters' questions.

Cosby is accused of drugging and violating former Temple University athletics employee Andrea Constand at his suburban Philadelphia mansion in 2004.

In a barrage of allegations that have destroyed Cosby's image as America's Dad, dozens of women have accused the former TV star of drugging and sexually assaulting them since the 1960s. But this is the only case in which he has been charged.

Cosby's lawyers contend that he had a deal with then-district attorney Bruce L Castor Jr in 2005 that he would not be prosecuted and that he could testify freely in Ms Constand's legal case. Mr Castor said at the time that there was insufficient evidence to charge Cosby.

Damaging testimony from that case was released last summer, prompting Mr Castor's successors to reopen the case and ultimately charge Cosby. He could get 10 years in prison if convicted.

Cosby admitted in the deposition that he had affairs with young models and actresses, that he obtained quaaludes to give to women he wanted to have sex with and that he gave Ms Constand three pills at his home. He said he reached into her pants in what he insisted was consensual contact.

In an unusual twist, Mr Castor was called to the stand at the hearing. Mr Castor has insisted that he worked out an oral "non-prosecution" agreement in 2005 with Walter M Phillips Jr, a Cosby lawyer who died last year.

Mr Castor was not immediately asked about such an agreement on Tuesday. But he defended his decision not to bring charges, testifying that he saw Ms Constand's year-long delay in reporting the allegations, inconsistencies in her statements, and her contact with a lawyer before going to police as red flags.

Still, Mr Castor said he investigated the case thoroughly because he wanted to show authorities in Ms Constand's native Canada that celebrities do not get preferential treatment in America.

Kevin Steele, the newly elected DA who is pursuing the case, has said Cosby would need an immunity agreement in writing to get the case thrown out. He has said he has no evidence one exists.

Anne Poulin, a law professor at Villanova University, said the defence has a high bar to meet to get the case thrown out early on. But "if they can win without this ever going to trial, then they've done their client a big service".