{"record":{"id":"b3c1ff55db7c0959","repo":"dotnet/wpf","slug":"sr-parserbamlversion-0-1","errorCode":null,"errorMessage":"SR.ParserBamlVersion: {0} {1}","messagePattern":"SR\\.ParserBamlVersion: (.+?) (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"critical","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlVersionHeader.cs","lineNumber":80,"sourceCode":"        {\n#if DEBUG\n            long posStart = bamlBinaryReader.BaseStream.Position;\n#endif\n\n            BamlVersion = FormatVersion.LoadFromStream(bamlBinaryReader.BaseStream);\n\n#if DEBUG\n            long posEnd = bamlBinaryReader.BaseStream.Position;\n            Debug.Assert((posEnd-posStart) == BamlVersionHeader.BinarySerializationSize,\n                             \"Incorrect Baml Version Header Size\");\n#endif\n\n            // We're assuming that only major versions are significant for compatibility,\n            // so if we have a major version in the file that is higher than that in\n            // the code, we can't read it.\n            if (BamlVersion.ReaderVersion != BamlWriterVersion)\n            {\n                throw new InvalidOperationException(SR.Format(SR.ParserBamlVersion,\n                                         (BamlVersion.ReaderVersion.Major.ToString(CultureInfo.CurrentCulture) + \".\" +\n                                          BamlVersion.ReaderVersion.Minor.ToString(CultureInfo.CurrentCulture)),\n                                         (BamlWriterVersion.Major.ToString(CultureInfo.CurrentCulture) + \".\" +\n                                          BamlWriterVersion.Minor.ToString(CultureInfo.CurrentCulture))));\n            }\n        }\n#endif\n\n\n        internal void WriteVersion(BinaryWriter bamlBinaryWriter)\n        {\n#if DEBUG\n            long posStart = bamlBinaryWriter.BaseStream.Position;\n#endif\n            BamlVersion.SaveToStream(bamlBinaryWriter.BaseStream);\n\n#if DEBUG\n            long posEnd = bamlBinaryWriter.BaseStream.Position;","sourceCodeStart":62,"sourceCodeEnd":98,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlVersionHeader.cs#L62-L98","documentation":"BamlVersionHeader.LoadVersion throws InvalidOperationException(SR.ParserBamlVersion) when the BAML file's BamlWriterVersion differs from the reader's BamlVersion.ReaderVersion. Only major version compatibility is assumed, so a BAML written by an incompatible major version cannot be read.","triggerScenarios":"Loading a BAML stream whose header major version (from BamlVersionHeader) is not equal to the runtime reader's BamlVersion.ReaderVersion — typically a BAML compiled with a different .NET/WPF major version.","commonSituations":"Deploying assemblies compiled against a newer .NET than the runtime, or consuming precompiled BAML resources (e.g. from a shared library) with an older framework; framework upgrades where stale satellite/old-build resources remain.","solutions":["Recompile the XAML/BAML with the same .NET version as the deployment runtime","Ensure the runtime machine has the framework version the app was built against","Clean stale resources: delete old obj/bin and re-deploy so no old-version BAML ships","If versions must differ, ship loose XAML (XamlReader.Load) instead of precompiled BAML"],"exampleFix":"// before: built on net8, deployed on net6 runtime\n// after: align versions\n<TargetFramework>net6.0</TargetFramework> <!-- build and run on same TFM -->","handlingStrategy":"validation","validationCode":"// check BAML header version before loading (must match BamlVersion.ReaderVersion major)\n// read the BamlVersionHeader first; abort with a friendly message if majors differ","typeGuard":null,"tryCatchPattern":"try { LoadBaml(stream); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"version\")) {\n    throw new DeploymentException(\"BAML was compiled with an incompatible framework version — redeploy rebuilt assemblies\", ex);\n}","preventionTips":["Build TFM must equal deployment runtime TFM","Clean obj/bin and redeploy on framework upgrades","Never ship precompiled BAML across different .NET major versions"],"tags":["wpf","baml","version-mismatch","compatibility"],"backgroundTag":"incompatible-source-type","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-21T21:30:21.729Z"}