antlr/antlr4 · error · NotSupportedException

there is no serialized ATN

Error message

there is no serialized ATN

What it means

Error "there is no serialized ATN" thrown in antlr/antlr4.

Source

Thrown at runtime/CSharp/src/Recognizer.cs:140

            return TokenConstants.InvalidType;
        }

        /// <summary>
        /// If this recognizer was generated, it will have a serialized ATN
        /// representation of the grammar.
        /// </summary>
        /// <remarks>
        /// If this recognizer was generated, it will have a serialized ATN
        /// representation of the grammar.
        /// <p>For interpreters, we don't know their serialized ATN despite having
        /// created the interpreter from it.</p>
        /// </remarks>
        public virtual int[] SerializedAtn
        {
            [return: NotNull]
            get
            {
                throw new NotSupportedException("there is no serialized ATN");
            }
        }

        /// <summary>For debugging and other purposes, might want the grammar name.</summary>
        /// <remarks>
        /// For debugging and other purposes, might want the grammar name.
        /// Have ANTLR generate an implementation for this method.
        /// </remarks>
        public abstract string GrammarFileName
        {
            get;
        }

        /// <summary>
        /// Get the
        /// <see cref="Antlr4.Runtime.Atn.ATN"/>
        /// used by the recognizer for prediction.
        /// </summary>

View on GitHub (pinned to 7d5770395b)

Solutions

  1. Construct the recognizer with a serialized ATN (generated code does this); do not call ATN accessors on a recognizer built without one.
  2. Regenerate the recognizer with the ANTLR tool so the static _ATN field is initialized.

Example fix

// use generated parser; it passes 'new ATNDeserializer().Deserialize(_serializedATN)' to base

When it happens

Trigger: Recognizer.SerializedAtn accessed but the recognizer has no serialized ATN data.

Common situations: Ensure the generated recognizer includes _serializedATN; use the ATNDeserializer only when serialized ATN exists.


AI-assisted analysis of antlr/antlr4@7d5770395b (2026-08-14). Data as JSON: /api/errors/ebb20f9efcd1287b. Report an issue: GitHub.