A black lawyer has filed a complaint against a Maryland sheriff's deputy who detained him in court thinking he was a suspect in a case and did not believe he was an attorney.

In a complaint, Rashad James with the Maryland Legal Aid said a Harford County deputy thought he was his client impersonating a lawyer and questioned him at the county courthouse. James' client is also black but was not present at the hearing March 6 to file a petition for expungement — which was granted — the attorney told NBCBLK.

After a successful hearing, James says the officer didn't believe his driver's license was valid. He says he was the only black attorney in the courtroom and it was his first time representing a client in Harford County.

“This is actually the first time this has occurred to me, and I do not know of any colleagues who have had a similar experience,” James said in an interview with the Baltimore Sun. “In the moment, it was sort of surreal, in the sense that I guess it was just one of those unexpected things that I just did not anticipate.”

James says the deputy's actions were racially motivated, and his complaint asks for an internal investigation and a record made in the officer's personnel file.

In a statement, Sheriff Jeffrey Gahler said his office is investigating.

"As with all complaints, the complaint filed on behalf of Mr. James was promptly assigned to the Harford County Sheriff’s Office - Office of Professional Standards for a complete and thorough investigation," Gahler said. "We take all complaints seriously."

Brown Goldstein Levy, the law firm that is representing James, is referring to the incident as "lawyering while black." In the last year, several instances of white Americans calling police on African-Americans for doing everyday actions such as sitting in a Starbucks store or leaving an Airbnb location have made national headlines. On Twitter, the hashtag #WhileBlack has gone viral, where black people have shared personal stories of having their activities questioned in ways that were uncomfortable or threatening.

"It’s just another example of African-American men doing ordinary things and being viewed skeptically," Chelsea Crawford, an attorney representing James, said. "You can add lawyering while black to the ever-growing list of things that black men do that they get questioned for."

Crawford said she hopes the Harford County Sheriff's Office will institute sensitivity trainings for its officers to help check biases against black people and other people of color.

James said he is ready to turn the focus back on to his clients, but encourages other people who experience these biases to report them.

"Have the confidence to speak up," he said. "I am an advocate who speaks up on behalf of my clients. This was an opportunity to speak up for myself."

Follow NBCBLK on Facebook, Twitter and Instagram