{"record":{"id":"d32220ed002796b6","repo":"dotnet/wpf","slug":"notimplementedexception-bamlrecordreader","errorCode":null,"errorMessage":"NotImplementedException","messagePattern":"NotImplementedException","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecordReader.cs","lineNumber":1707,"sourceCode":"                BaseReadDeferableContentStart(bamlRecord, out defKeyList, out staticResourceValuesList);\n\n                // If we don't own the stream, someone might close it when the parse is complete,\n                // so copy the defer load contents into a buffer.  If we own the\n                // stream, then we'll assume the owner will keep it open.\n                long endOfKeysPosition = stream.Position;\n                Int32 valuesSize = (Int32)(bamlRecord.ContentSize - endOfKeysPosition + startPosition);\n\n                if (!ParserContext.OwnsBamlStream)\n                {\n                    byte[] buffer = new byte[valuesSize];\n\n                    if (valuesSize > 0)\n                    {\n                        MS.Internal.IO.Packaging.PackagingUtilities.ReliableRead(\n                            BinaryReader, buffer, 0, valuesSize);\n                    }\n\n                    throw new NotImplementedException();\n                    //dictionary.SetDeferableContent(buffer,\n                    //        ParserContext, _rootElement, defKeyList, staticResourceValuesList);\n                }\n                else\n                {\n                    throw new NotImplementedException();\n                    //dictionary.SetDeferableContent(_bamlStream,\n                    //        endOfKeysPosition, valuesSize,\n                    //        ParserContext, _rootElement, defKeyList, staticResourceValuesList);\n\n                    //_bamlStream.Seek(valuesSize, SeekOrigin.Current);\n                }\n            }\n        }\n\n        internal void BaseReadDeferableContentStart(\n            BamlDeferableContentStartRecord bamlRecord,\n            out ArrayList                   defKeyList,","sourceCodeStart":1689,"sourceCodeEnd":1725,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecordReader.cs#L1689-L1725","documentation":"BamlRecordReader.ReadOptimizedStaticContent throws NotImplementedException for the deferring-branch that was never implemented (the SetDeferableContent call is commented out). It performs the ReliableRead into a scratch buffer first, then unconditionally throws, meaning this BAML content-loading path is not supported in the current framework version.","triggerScenarios":"Loading BAML whose optimized static-content section requires reading deferred dictionary values from an in-memory buffer (valuesSize > 0 branch) — the reader reaches ReadOptimizedStaticContent with a deferred-key dictionary whose values must be read from a buffer.","commonSituations":"BAML produced by toolchains or scenarios that emit buffered optimized static content the runtime reader never implemented; custom BAML tooling or cross-version loading of deferred resource dictionaries.","solutions":["Remove or rewrite the XAML so it avoids the optimized deferred static-content path (e.g. non-deferred ResourceDictionary)","Compile and run with the same framework version; check for known fixes in newer .NET releases","Split resource dictionaries so keys are resolved eagerly instead of via optimized static content","If unavoidable, report the repro to the WPF repo — this is a framework limitation, not user error"],"exampleFix":"// before: deferred optimized static resource in dictionary\n<ResourceDictionary><x:Static Member=\"lib:Foo.Bar\"/></ResourceDictionary>\n// after: eager instance resource\n<ResourceDictionary><lib:Foo /></ResourceDictionary>","handlingStrategy":"try-catch","validationCode":"// avoid constructs that trigger optimized deferred static content; prefer plain StaticResource/direct instances in ResourceDictionary XAML","typeGuard":null,"tryCatchPattern":"try { LoadBaml(stream); }\ncatch (NotImplementedException) {\n    // fall back to loading loose XAML via XamlReader.Load on the original .xaml\n    return XamlReader.Load(new StringReader(originalXaml));\n}","preventionTips":["Avoid optimized/deferred static-content BAML paths","Align build and runtime framework versions","Keep resource dictionaries simple and eager"],"tags":["wpf","baml","not-implemented","unimplemented-path"],"backgroundTag":"method-not-implemented","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}