dotnet/wpf · warning · NotImplementedException
throw new NotImplementedException();
Error message
throw new NotImplementedException();
What it means
XamlFrame.Clone is a virtual placeholder that intentionally throws NotImplementedException; only subclasses that need cloning (e.g. ObjectWriterFrame) override it. Calling Clone on a base XamlFrame (or a subclass that never overrides) is unsupported by design.
Solutions
- Only call Clone on frame types known to override it (e.g. ObjectWriterFrame)
- Check the concrete type before calling Clone, or add an override in your frame subclass
- Use frame Reset() on the existing stack instead of cloning when reuse is the goal
- Wrap in try-catch for NotImplementedException when frames are processed generically
Example fix
// before var copy = frame.Clone(); // after var copy = frame is ObjectWriterFrame owf ? owf.Clone() : null;
Defensive patterns
Strategy: fallback
Validate before calling
static bool SupportsClone(MS.Internal.Xaml.Context.XamlFrame f) =>
f.GetType().GetMethod("Clone").DeclaringType != f.GetType().GetTypeInfo().BaseType && f.GetType().GetMethod("Clone").IsOverridden();
// simpler: f is MS.Internal.Xaml.Context.ObjectWriterFrame Type guard
static bool CanClone(XamlFrame f) => f is ObjectWriterFrame;
Try / catch
try { copy = frame.Clone(); }
catch (NotImplementedException) { /* fall back to Reset() reuse or skip cloning */ } Prevention
- Only clone frame types that document a Clone override
- Use Reset() for frame reuse instead of cloning
- When adding XamlFrame subclasses, override Clone if instances will be copied
When it happens
Trigger: Invoking Clone() on a XamlFrame instance whose concrete type does not override Clone — typically the abstract base or a lightweight frame type used in the XAML parser stack.
Common situations: Custom XAML parser/object-writer extensions calling Clone generically on any frame in the stack; reflection-based code copying frames without checking the concrete type.
Related errors
- ArgumentException: path
- ArgumentException: relativeTo
- ArgumentNullException: path
- ArgumentNullException: relativeTo
- NotImplementedException
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/bc5f458bad2b993a.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Xaml/Context/XamlFrame.cs:29
private XamlFrame _previous;
protected XamlFrame()
{
_depth = -1;
}
// Copy constructor
protected XamlFrame(XamlFrame source)
{
_depth = source._depth;
}
public virtual XamlFrame Clone()
{
// Clone should only be overridden for the classes that really need it
// ObjectWriterFrame overrides this so we can reuse the context for
// Templates.
throw new NotImplementedException();
}
// Reset the contents of the Frame so it can be reused in a stack without reallocating.
// Depth and previous do not change when we reuse the Frame.
public abstract void Reset();
public int Depth
{
get
{
Debug.Assert(_depth != -1, "Context Frame is uninitialized");
return _depth;
}
}
public XamlFrame Previous
{
get { return _previous; }View on GitHub (pinned to 81131a70a4)