antlr/antlr4 · critical · ArgumentException

The specified transition type is not valid.

Error message

The specified transition type is not valid.

What it means

ATNDeserializer.EdgeFactory switches on the serialized transition type to build the right Transition subclass; the fall-through after the switch throws ArgumentException('The specified transition type is not valid.') for an unrecognized transition type byte. Valid types are EPSILON, RULE, PREDICATE, ATOM, RANGE, ACTION, SET, NOT_SET, WILDCARD, PRECEDENCE — a value outside this set means the data is corrupt or from an incompatible serialization.

Source

Thrown at runtime/CSharp/src/Atn/ATNDeserializer.cs:1031

                    return a;
                }

                case TransitionType.SET:
                {
                    return new SetTransition(target, sets[arg1]);
                }

                case TransitionType.NOT_SET:
                {
                    return new NotSetTransition(target, sets[arg1]);
                }

                case TransitionType.WILDCARD:
                {
                    return new WildcardTransition(target);
                }
            }
            throw new ArgumentException("The specified transition type is not valid.");
        }

        protected internal virtual ATNState StateFactory(StateType type, int ruleIndex)
        {
            ATNState s;
            switch (type)
            {
                case StateType.InvalidType:
                {
                    return null;
                }

                case StateType.Basic:
                {
                    s = new BasicState();
                    break;
                }

View on GitHub (pinned to 7d5770395b)

Solutions

  1. Regenerate all parsers/lexers with the tool version matching the runtime and rebuild
  2. Ensure the serialized ATN data reaches the deserializer intact (no truncation, correct encoding)
  3. Align every project in the solution on one Antlr4.Runtime version
Defensive patterns

Strategy: try-catch

Try / catch

try { new ATNDeserializer().Deserialize(data); } catch (ArgumentException e) { /* transition type out of range: serialized ATN corrupt or version-mismatched; regenerate */ }

Prevention

When it happens

Trigger: Deserializing an ATN whose transition type field is out of range — truncated/mismatched serialized ATN data, or ATN bytes generated by a different ANTLR serialization version.

Common situations: Tool/runtime version mismatch (most common), hand-crafted or copied serialized ATN strings that got corrupted, or a partially regenerated grammar where lexer and parser ATNs come from different versions.

Related errors


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