There's no guarantee of anything when it comes to the courts -- other than you'll be spending all your money to prove you shouldn't have been in court in the first place.
If you happen to be advised by your lawyer in writing, and you followed that advice, as long as the violation wasn't something a layman should know is illegal (like murder or stealing a car), then you actually have a defense.
You can also sue your lawyer for malpractice and file a complaint with the state bar.
If you can prove the elements of legal malpractice, that's grounds for appeal, either to set the verdict aside or for a retrial, depending on the prosecutor's intentions for refiling.
If you get your "misunderstanding" from a government entity it can be a defense though. I am not sure if the defense of "the police officer told me it was legal" has ever been used or ever succeeded though.
§702-220 Ignorance or mistake of law; belief that conduct not legally prohibited. In any prosecution, it shall be an affirmative defense that the defendant engaged in the conduct or caused the result alleged under the belief that the conduct or result was not legally prohibited when the defendant acts in reasonable reliance upon an official statement of the law, afterward determined to be invalid or erroneous, contained in:
(1) A statute or other enactment;
(2) A judicial decision, opinion, or judgment;
(3) An administrative order or administrative grant of permission; or
(4) An official interpretation of the public officer or body charged by law with responsibility for the interpretation, administration, or enforcement of the law defining the offense.