dotnet/wpf · error · NotImplementedException
NotImplementedException
Error message
NotImplementedException
What it means
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.
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
Example fix
// before: deferred optimized static resource in dictionary <ResourceDictionary><x:Static Member="lib:Foo.Bar"/></ResourceDictionary> // after: eager instance resource <ResourceDictionary><lib:Foo /></ResourceDictionary>
Defensive patterns
Strategy: try-catch
Validate before calling
// avoid constructs that trigger optimized deferred static content; prefer plain StaticResource/direct instances in ResourceDictionary XAML
Try / catch
try { LoadBaml(stream); }
catch (NotImplementedException) {
// fall back to loading loose XAML via XamlReader.Load on the original .xaml
return XamlReader.Load(new StringReader(originalXaml));
} Prevention
- Avoid optimized/deferred static-content BAML paths
- Align build and runtime framework versions
- Keep resource dictionaries simple and eager
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- 0x80004001
- ArgumentException: path
- ArgumentException: relativeTo
- ArgumentNullException: path
- ArgumentNullException: relativeTo
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/d32220ed002796b6.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/BamlRecordReader.cs:1707
BaseReadDeferableContentStart(bamlRecord, out defKeyList, out staticResourceValuesList);
// If we don't own the stream, someone might close it when the parse is complete,
// so copy the defer load contents into a buffer. If we own the
// stream, then we'll assume the owner will keep it open.
long endOfKeysPosition = stream.Position;
Int32 valuesSize = (Int32)(bamlRecord.ContentSize - endOfKeysPosition + startPosition);
if (!ParserContext.OwnsBamlStream)
{
byte[] buffer = new byte[valuesSize];
if (valuesSize > 0)
{
MS.Internal.IO.Packaging.PackagingUtilities.ReliableRead(
BinaryReader, buffer, 0, valuesSize);
}
throw new NotImplementedException();
//dictionary.SetDeferableContent(buffer,
// ParserContext, _rootElement, defKeyList, staticResourceValuesList);
}
else
{
throw new NotImplementedException();
//dictionary.SetDeferableContent(_bamlStream,
// endOfKeysPosition, valuesSize,
// ParserContext, _rootElement, defKeyList, staticResourceValuesList);
//_bamlStream.Seek(valuesSize, SeekOrigin.Current);
}
}
}
internal void BaseReadDeferableContentStart(
BamlDeferableContentStartRecord bamlRecord,
out ArrayList defKeyList,View on GitHub (pinned to 81131a70a4)