{"record":{"id":"b61fb8c94e446cc6","repo":"antlr/antlr4","slug":"could-not-deserialize-atn-with-version-0-expect","errorCode":null,"errorMessage":"Could not deserialize ATN with version {0} (expected {1}).","messagePattern":"Could not deserialize ATN with version (.+?) \\(expected (.+?)\\)\\.","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"critical","filePath":"runtime/CSharp/src/Atn/ATNDeserializer.cs","lineNumber":454,"sourceCode":"\t\t\t\tint stateNumber = ReadInt();\n\t\t\t\t((RuleStartState)atn.states[stateNumber]).isPrecedenceRule = true;\n\t\t\t}\n\t\t}\n\n\t\tprotected internal virtual ATN ReadATN()\n\t\t{\n\t\t\tATNType grammarType = (ATNType)ReadInt();\n\t\t\tint maxTokenType = ReadInt();\n\t\t\treturn new ATN(grammarType, maxTokenType);\n\t\t}\n\n\t\tprotected internal virtual void CheckVersion()\n\t\t{\n\t\t\tint version = ReadInt();\n\t\t\tif (version != SerializedVersion)\n\t\t\t{\n\t\t\t\tstring reason = string.Format(CultureInfo.CurrentCulture, \"Could not deserialize ATN with version {0} (expected {1}).\", version, SerializedVersion);\n\t\t\t\tthrow new NotSupportedException(reason);\n\t\t\t}\n\t\t}\n\n        /// <summary>\n        /// Analyze the\n        /// <see cref=\"StarLoopEntryState\"/>\n        /// states in the specified ATN to set\n        /// the\n        /// <see cref=\"StarLoopEntryState.isPrecedenceDecision\"/>\n        /// field to the\n        /// correct value.\n        /// </summary>\n        /// <param name=\"atn\">The ATN.</param>\n        protected internal virtual void MarkPrecedenceDecisions(ATN atn)\n        {\n            foreach (ATNState state in atn.states)\n            {\n                if (!(state is StarLoopEntryState))","sourceCodeStart":436,"sourceCodeEnd":472,"githubUrl":"https://github.com/antlr/antlr4/blob/7d5770395bb7b02eb56e7c62662cb1d7c08f42a3/runtime/CSharp/src/Atn/ATNDeserializer.cs#L436-L472","documentation":"ATNDeserializer.CheckVersion reads a leading version int from the serialized ATN and compares it to SerializedVersion. A mismatch throws NotSupportedException with both numbers — the serialized ATN is from an incompatible ANTLR version and cannot be interpreted by this runtime.","triggerScenarios":"Generated parser .cs files containing a serialized ATN from ANTLR 4.x being loaded by a runtime whose SerializedVersion differs (e.g. ATN format changed across major/minor releases).","commonSituations":"Upgrading the Antlr4.Runtime NuGet package without regenerating parsers (or vice versa); generated code checked in from a teammate using a different tool version.","solutions":["Regenerate the parser with the ANTLR tool version that matches the runtime package exactly","Pin both the codegen Maven/NuGet build-time package and the runtime to the same version","Delete old generated files so regeneration is guaranteed"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { new ATNDeserializer().Deserialize(data); } catch (NotSupportedException e) { /* parse 'version X (expected Y)' from message; align tool and runtime versions */ }","preventionTips":["Treat ANTLR tool and runtime versions as a locked pair in build config","Never mix generated files from different ANTLR versions in one commit"],"tags":["antlr","atn","version-mismatch","csharp"],"backgroundTag":null,"analyzedSha":"7d5770395bb7b02eb56e7c62662cb1d7c08f42a3","analyzedAt":"2026-08-14T14:47:56.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}