{"record":{"id":"dc16988872c3432e","repo":"dotnet/wpf","slug":"sr-parserunknownbaml-0","errorCode":null,"errorMessage":"SR.ParserUnknownBaml: {0}","messagePattern":"SR\\.ParserUnknownBaml: (.+?)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs","lineNumber":657,"sourceCode":"                        ReadConstructorStart();\n                        break;\n\n                    case BamlRecordType.ConstructorParametersEnd:\n                        ReadConstructorEnd();\n                        break;\n\n                    case BamlRecordType.ConnectionId:\n                        ReadConnectionIdRecord();\n                        break;\n\n                    case BamlRecordType.StaticResourceId:\n                        ReadStaticResourceId();\n                        keepOnReading = true;\n                        break;\n\n                    default:\n                        // Can't have any other type of record at this point.\n                        throw new InvalidOperationException(SR.Format(SR.ParserUnknownBaml,\n                                         ((int)_currentBamlRecord.RecordType).ToString(CultureInfo.CurrentCulture)));\n                }\n            }\n        }\n\n        /***************************************************************************\\\n        *\n        * BamlReader.ReadProperties\n        *\n        * This is called when an element start has been encountered (or something\n        * similar) and a number of properties may or may not follow.  Read all the\n        * properties, storing them in the _properties arraylist.  When a non-property\n        * record is encountered, stop, but store that record as the\n        * _currentBamlRecord.\n        *\n        \\***************************************************************************/\n\n        private void ReadProperties()","sourceCodeStart":639,"sourceCodeEnd":675,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlReader.cs#L639-L675","documentation":"ReadNextRecord dispatches on the current BAML record type; the switch's default case exists because an unrecognized BamlRecordType cannot appear in a well-formed stream. Encountering one means the BAML is corrupt or was produced by a newer compiler whose record types this reader does not understand, so it throws InvalidOperationException(SR.ParserUnknownBaml) with the numeric record type.","triggerScenarios":"Parsing a BAML stream containing a record type absent from the reader's switch — typically BAML compiled by a newer .NET/WPF version than the runtime parsing it, or a corrupted/truncated stream misaligned on record boundaries.","commonSituations":"Version skew: precompiled BAML (from a newer framework or third-party tool) loaded by an older runtime; manually edited or damaged assembly resources; fuzzing/custom BAML generators emitting invalid record types.","solutions":["Recompile the BAML/XAML with the markup compiler matching the runtime version loading it.","Ensure the runtime framework version is >= the version that produced the BAML.","Restore/replace the corrupted assembly or .baml resource.","If writing tooling, validate record boundaries before dispatch and log the unknown RecordType value instead of assuming valid input."],"exampleFix":"// before\n// loading BAML built with newer-framework record types on an older runtime\n// after\n// rebuild the XAML with the target framework's PresentationBuildTasks so emitted record types match the reader","handlingStrategy":"try-catch","validationCode":"// No pre-call validation possible for stream contents; verify version instead:\n// ensure the assembly containing the BAML was built with a markup compiler <= the runtime version.","typeGuard":null,"tryCatchPattern":"try { while (reader.Read()) { } }\ncatch (InvalidOperationException ex) when (ex.Message.StartsWith(\"ParserUnknownBaml\") || ex.Message.Contains(\"record\"))\n{\n    // BAML from an incompatible/newer compiler or corrupt; recompile or reload resource\n}","preventionTips":["Keep the runtime's WPF version >= the version of the tooling that produced the BAML.","Rebuild XAML into BAML with the matching target framework's build tasks.","Treat 'unknown BAML record type' as a corrupt/mismatched-resource signal; replace the binary."],"tags":["wpf","baml","parser","version-mismatch","corruption"],"backgroundTag":"unexpected-response-shape","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"}