Minn. Stat. § 630.18
In addition to the grounds for dismissal of an indictment specified in rules 17.06, subdivision 2, and 18.09, subdivision 2, of the Rules of Criminal Procedure and subject to the provisions of rules 17.06, subdivision 1, and 31.01, of the Rules of Criminal Procedure, the indictment shall be dismissed by the court in which the defendant is arraigned, upon the defendant's motion, in any of the following cases:
(8) when the indictment contains any matter which, if true, would constitute a legal justification or excuse of the offense charged, or other legal bar to the prosecution.
If the motion to dismiss the indictment is not made, the defendant shall be precluded from afterwards making any of the foregoing objections except that the objection to lack of jurisdiction specified in clause (4) and the objection of failure of the indictment to include facts stating a public offense specified in clause (7) shall be noticed by the court at any time during the pendency of a proceeding. Failure to include any objections constitutes a waiver thereof, but the court for good cause shown may, in accordance with rule 10.01, subdivision 2, of the Rules of Criminal Procedure, grant relief from the waiver.