{"record":{"id":"2d360e4a1bed5a64","repo":"antlr/antlr4","slug":"the-specified-lexer-action-type-0-is-not-valid","errorCode":null,"errorMessage":"The specified lexer action type {0} is not valid.","messagePattern":"The specified lexer action type (.+?) is not valid\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"critical","filePath":"runtime/CSharp/src/Atn/ATNDeserializer.cs","lineNumber":1173,"sourceCode":"                case LexerActionType.PushMode:\n                {\n                    return new LexerPushModeAction(data1);\n                }\n\n                case LexerActionType.Skip:\n                {\n                    return LexerSkipAction.Instance;\n                }\n\n                case LexerActionType.Type:\n                {\n                    return new LexerTypeAction(data1);\n                }\n\n                default:\n                {\n                    string message = string.Format(CultureInfo.CurrentCulture, \"The specified lexer action type {0} is not valid.\", type);\n                    throw new ArgumentException(message);\n                }\n            }\n        }\n    }\n}\n","sourceCodeStart":1155,"sourceCodeEnd":1179,"githubUrl":"https://github.com/antlr/antlr4/blob/7d5770395bb7b02eb56e7c62662cb1d7c08f42a3/runtime/CSharp/src/Atn/ATNDeserializer.cs#L1155-L1179","documentation":"Thrown by ATNDeserializer.LexerActionFactory when the serialized ATN contains a lexer action type byte that does not correspond to any known LexerActionType (Channel, Custom, Mode, More, PushMode, PopMode, Skip, Type). Lexer actions are the skip(), mode(), more(), channel(), type() commands compiled into lexer rules; an unknown action type means the serialized ATN data is not one this runtime knows how to turn into ILexerAction instances.","triggerScenarios":"Deserializing a serialized ATN whose lexer-action opcode byte falls outside the recognized enum, i.e. the default branch of LexerActionFactory's switch. Occurs with a tool/runtime version mismatch (a newer tool emitted a new action opcode the older runtime does not know), corrupted generated ATN constants, or a hand-built serialized ATN array with an invalid action opcode.","commonSituations":"Upgrading the ANTLR codegen tool but not the runtime (or the reverse); editing generated lexer files manually; using a serialized ATN produced for a different language runtime whose action encoding differs.","solutions":["Align the ANTLR codegen tool version and the Antlr4.Runtime NuGet package to the same release, then regenerate all lexer/parser sources","Restore the generated lexer file from source control if the serialized ATN constant was modified or partially merged","If you construct the ATN yourself, check every lexer action opcode you emit against the LexerActionType enum supported by the runtime you ship"],"exampleFix":"// before\n// lexer generated by antlr tool 4.13, runtime pinned to 4.6.6\nvar interp = new LexerInterpreter(name, vocab, rules, modes, atn, input); // throws\n\n// after\n// pin both to the same version and regenerate\n// <PackageReference Include=\"Antlr4.Runtime\" Version=\"4.13.1\" /> + Antlr4.Codegen 4.13.1","handlingStrategy":"validation","validationCode":"// Before interpreting a serialized ATN, verify producer/runtime versions agree\nif (GeneratedAtn.ToolVersion != RuntimeVersionInfo.ThisRuntime)\n    throw new InvalidOperationException($\"ATN built by {GeneratedAtn.ToolVersion}, runtime is {RuntimeVersionInfo.ThisRuntime}; regenerate sources.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Upgrade tool and runtime together as a single change set","Add a smoke test that constructs every generated lexer and parses a trivial input after version upgrades","Keep serialized ATN data out of hand-edited files"],"tags":["antlr","csharp","lexer","atn","deserialization","version-mismatch"],"backgroundTag":null,"analyzedSha":"7d5770395bb7b02eb56e7c62662cb1d7c08f42a3","analyzedAt":"2026-08-14T14:47:56.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}