antlr/antlr4 · critical · NotSupportedException
Couldn't identify final state of the precedence rule prefix
Error message
Couldn't identify final state of the precedence rule prefix section.
What it means
While preprocessing a left-recursive rule's ATN, the deserializer scans the star-loop states of the precedence-rule prefix section to find its end state (a LoopEndState whose first transition targets a RuleStopState). If no candidate matches, the serialized ATN does not have the expected shape and NotSupportedException is thrown — effectively a data/version corruption signal.
Source
Thrown at runtime/CSharp/src/Atn/ATNDeserializer.cs:135
}
if (!(state_3 is StarLoopEntryState))
{
continue;
}
ATNState maybeLoopEndState = state_3.Transition(state_3.NumberOfTransitions - 1).target;
if (!(maybeLoopEndState is LoopEndState))
{
continue;
}
if (maybeLoopEndState.epsilonOnlyTransitions && maybeLoopEndState.Transition(0).target is RuleStopState)
{
endState = state_3;
break;
}
}
if (endState == null)
{
throw new NotSupportedException("Couldn't identify final state of the precedence rule prefix section.");
}
excludeTransition = ((StarLoopEntryState)endState).loopBackState.Transition(0);
}
else
{
endState = atn.ruleToStopState[i_13];
}
// all non-excluded transitions that currently target end state need to target blockEnd instead
foreach (ATNState state_4 in atn.states)
{
foreach (Transition transition in state_4.transitions)
{
if (transition == excludeTransition)
{
continue;
}
if (transition.target == endState)
{View on GitHub (pinned to 7d5770395b)
Solutions
- Regenerate all parsers/lexers with the tool version matching the Antlr4.Runtime package and rebuild
- Remove stale generated files and bin/obj so no old serialized ATN survives
- Verify only one consistent ANTLR version is referenced across the solution
Defensive patterns
Strategy: try-catch
Try / catch
try { new ATNDeserializer().Deserialize(data); } catch (NotSupportedException e) { /* ATN shape unrecognized: regenerate parsers with matching tool/runtime version */ } Prevention
- Pin codegen and runtime to the same ANTLR version
- Regenerate all grammars and clean outputs after any ANTLR upgrade
When it happens
Trigger: Deserializing serialized ATN data produced by a different ANTLR version or tampered/truncated; a left-recursive rule's generated ATN not matching the C# runtime's expectations.
Common situations: Antlr4.Runtime NuGet version differing from the code generator version, stale generated .cs files after an upgrade, or hand-crafted ATN byte arrays.
Related errors
- Could not deserialize ATN with version {0} (expected {1}).
- The specified transition type is not valid.
- The specified state type {0} is not valid.
- The specified lexer action type {0} is not valid.
- Unrecognized ATN transition type.
AI-assisted analysis of antlr/antlr4@7d5770395b (2026-08-14).
Data as JSON: /api/errors/706c081e7484bccc.
Report an issue: GitHub.