{"record":{"id":"622d797894134954","repo":"dotnet/wpf","slug":"sr-format-sr-unknownbamlrecord-recordtype","errorCode":null,"errorMessage":"SR.Format(SR.UnknownBamlRecord, recordType)","messagePattern":"SR\\.Format\\(SR\\.UnknownBamlRecord, recordType\\)","errorType":"exception","errorClass":"XamlParseException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006Reader.cs","lineNumber":672,"sourceCode":"                    break;\n\n                case Baml2006RecordType.LineNumberAndPosition:\n                    Process_LineNumberAndPosition();\n                    break;\n\n                case Baml2006RecordType.Comment:\n                    Process_Comment();\n                    break;\n\n                #endregion\n\n                case Baml2006RecordType.ConnectionId:\n                    Process_ConnectionId();\n                    break;\n\n                case Baml2006RecordType.Unknown:\n                default:\n                    throw new XamlParseException(string.Format(CultureInfo.CurrentCulture, SR.Format(SR.UnknownBamlRecord, recordType)));\n            }\n\n            return true;\n        }\n\n        // Have not seen a BAML file that has this...\n        private void Process_ProcessingInstruction()\n        {\n            throw new NotImplementedException();\n        }\n\n        // Have not seen a BAML file that has this...\n        private void Process_DefTag()\n        {\n            throw new NotImplementedException();\n        }\n\n        // Have not seen a BAML file that has this...","sourceCodeStart":654,"sourceCodeEnd":690,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/Baml2006/Baml2006Reader.cs#L654-L690","documentation":"The reader encountered a BAML record type it does not know (Baml2006RecordType.Unknown or an unhandled value) and throws XamlParseException wrapping SR.UnknownBamlRecord with the numeric record type. It means the BAML stream contains a record the loaded Wpf Xaml parser cannot interpret.","triggerScenarios":"Process_OneBamlRecord's switch (reached via ReadKeys, ReadObject, or Process_BamlRecords) falls into the default case because recordType is not one of the known Baml2006RecordType values.","commonSituations":"Loading BAML compiled by a newer .NET/WPF version than the runtime parsing it (forward-compatibility gap); corrupted resource stream; a tool rewrote record bytes and shifted the type codes.","solutions":["Update the runtime to a .NET/WPF version at least as new as the toolchain that compiled the BAML (align TargetFramework and installed runtime).","Rebuild the application so BAML is regenerated by the current SDK instead of loading stale compiled resources.","Check for resource corruption — compare the .baml bytes against a clean build.","If implementing custom BAML tooling, restrict emitted records to types known to the target Baml2006Reader version."],"exampleFix":"// before: csproj targets net472 but baml was compiled with net8.0 toolchain and deployed to net472\n<TargetFramework>net472</TargetFramework>\n// after\n<TargetFramework>net8.0</TargetFramework> <!-- match the SDK that produced the baml -->","handlingStrategy":"try-catch","validationCode":"// Ensure runtime is not older than the toolchain that compiled resources\nvar runtime = Environment.Version;\nif (runtime.Major < targetCompiledMajor) throw new PlatformNotSupportedException(\"BAML compiled by newer SDK\");","typeGuard":null,"tryCatchPattern":"try\n{\n    using var reader = new Baml2006Reader(stream);\n    while (reader.Read()) { }\n}\ncatch (XamlParseException ex) when (ex.Message.Contains(\"Unknown BAML record\"))\n{\n    // recordType number is embedded in the message; log it and advise upgrade\n    logger.LogError(ex, \"Unknown BAML record — runtime/toolchain version mismatch\");\n    throw;\n}","preventionTips":["Compile and run on the same .NET/WPF major version","Pin SDK versions in CI to match production runtime","Never consume BAML from newer assemblies on older runtimes","Log the record type number for triage"],"tags":["wpf","xaml","baml","version-mismatch"],"backgroundTag":"unsupported-enum-value","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"}