{"record":{"id":"ae039caf7a764561","repo":"antlr/antlr4","slug":"rule-dependency-version-mismatch-0-has-maximum","errorCode":null,"errorMessage":"Rule dependency version mismatch: {0} has maximum dependency version {1} (expected {2}) in {3}","messagePattern":"Rule dependency version mismatch: (.+?) has maximum dependency version (.+?) \\(expected (.+?)\\) in (.+?)","errorType":"validation","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"runtime/CSharp/src/Misc/RuleDependencyChecker.cs","lineNumber":172,"sourceCode":"                        {\n                            continue;\n                        }\n                        @checked.Set(descendant);\n                        int required = CheckDependencyVersion(errors, dependency, ruleNames, ruleVersions, descendant, \"descendant\");\n                        highestRequiredDependency = Math.Max(highestRequiredDependency, required);\n                    }\n                }\n                int declaredVersion = dependency.Item1.Version;\n                if (declaredVersion > highestRequiredDependency)\n                {\n                    string message = string.Format(\"Rule dependency version mismatch: {0} has maximum dependency version {1} (expected {2}) in {3}\", ruleNames[dependency.Item1.Rule], highestRequiredDependency, declaredVersion, dependency.Item1.Recognizer.ToString());\n                    errors.AppendLine(dependency.Item2.ToString());\n                    errors.AppendLine(message);\n                }\n            }\n            if (errors.Length > 0)\n            {\n                throw new InvalidOperationException(errors.ToString());\n            }\n        }\n\n        private static readonly Dependents ImplementedDependents = Dependents.Self | Dependents.Parents | Dependents.Children | Dependents.Ancestors | Dependents.Descendants;\n\n        private static void ReportUnimplementedDependents(StringBuilder errors, Tuple<RuleDependencyAttribute, ICustomAttributeProvider> dependency, Dependents dependents)\n        {\n            Dependents unimplemented = dependents;\n            unimplemented &= ~ImplementedDependents;\n            if (unimplemented != Dependents.None)\n            {\n                string message = string.Format(\"Cannot validate the following dependents of rule {0}: {1}\", dependency.Item1.Rule, unimplemented);\n                errors.AppendLine(message);\n            }\n        }\n\n        private static int CheckDependencyVersion(StringBuilder errors, Tuple<RuleDependencyAttribute, ICustomAttributeProvider> dependency, string[] ruleNames, int[] ruleVersions, int relatedRule, string relation)\n        {","sourceCodeStart":154,"sourceCodeEnd":190,"githubUrl":"https://github.com/antlr/antlr4/blob/7d5770395bb7b02eb56e7c62662cb1d7c08f42a3/runtime/CSharp/src/Misc/RuleDependencyChecker.cs#L154-L190","documentation":"Error \"Rule dependency version mismatch: {0} has maximum dependency version {1} (expected {2}) in {3}\" thrown in antlr/antlr4.","triggerScenarios":"RuleDependencyChecker encounters a @RuleDependency annotation whose version exceeds the recognized maximum for that rule.","commonSituations":"Align the dependency version in @RuleVersion/@RuleDependency annotations with the grammar's declared rule versions.","solutions":["Regenerate the ANTLR code with a runtime version compatible with the grammar's dependency version, or update the runtime to the expected version.","Align the RuleDependency attribute/annotation version in the grammar or recognizer with the expected serialized version.","Keep all generated recognizers and the runtime from the same ANTLR release."],"exampleFix":"// regenerate code with the same ANTLR version as the runtime, e.g.\n// dotnet antlr4 -Dlanguage=CSharp MyGrammar.g4  (matching Antlr4.Runtime.Standard version)","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7d5770395bb7b02eb56e7c62662cb1d7c08f42a3","analyzedAt":"2026-08-14T14:47:56.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}