North Carolina Attorney General Roy Cooper announced Tuesday his opposition to recently enacted legislation that nullified Charlotte's LGBT protections ordinance.

House Bill 2 – which was approved during a one-day special session – prohibits cities and towns from enacting measures that prohibit discrimination based on sexual orientation or gender identity and bars students attending public institutions from using the bathroom that does not conform to their gender at birth.

Cooper, a Democratic gubernatorial candidate, told reporters that he won't defend the measure in court.

“Over the last 15 years, our office has defended the state, it's officials and agencies when they've been sued. Our office will continue to do that, except it will not defend the constitutionality of the discrimination in House Bill 2,” Cooper told reporters during a press conference.

On Monday, four rights groups filed a legal challenge to the law.

(Related: Rights groups challenge North Carolina's anti-gay law.)

“Discrimination is wrong. Period. The governor and the legislature should repeal this law. Repeal will save needless litigation costs and will begin to repair our national reputation,” Cooper said.

Cooper in 2014 refused to defend the state's ban on gay marriage in court.