{"record":{"id":"bc5f458bad2b993a","repo":"dotnet/wpf","slug":"throw-new-notimplementedexception","errorCode":null,"errorMessage":"throw new NotImplementedException();","messagePattern":"throw new NotImplementedException\\(\\);","errorType":"exception","errorClass":"NotImplementedException","httpStatus":null,"severity":"warning","filePath":"src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Xaml/Context/XamlFrame.cs","lineNumber":29,"sourceCode":"        private XamlFrame _previous;\n\n        protected XamlFrame()\n        {\n            _depth = -1;\n        }\n\n        // Copy constructor\n        protected XamlFrame(XamlFrame source)\n        {\n            _depth = source._depth;\n        }\n\n        public virtual XamlFrame Clone()\n        {\n            // Clone should only be overridden for the classes that really need it\n            // ObjectWriterFrame overrides this so we can reuse the context for\n            // Templates.\n            throw new NotImplementedException();\n        }\n\n        // Reset the contents of the Frame so it can be reused in a stack without reallocating.\n        // Depth and previous do not change when we reuse the Frame.\n        public abstract void Reset();\n\n        public int Depth\n        {\n            get\n            {\n                Debug.Assert(_depth != -1, \"Context Frame is uninitialized\");\n                return _depth;\n            }\n        }\n\n        public XamlFrame Previous\n        {\n            get { return _previous; }","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/Shared/MS/Internal/Xaml/Context/XamlFrame.cs#L11-L47","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nvar copy = frame.Clone();\n// after\nvar copy = frame is ObjectWriterFrame owf ? owf.Clone() : null;","handlingStrategy":"fallback","validationCode":"static bool SupportsClone(MS.Internal.Xaml.Context.XamlFrame f) =>\n    f.GetType().GetMethod(\"Clone\").DeclaringType != f.GetType().GetTypeInfo().BaseType && f.GetType().GetMethod(\"Clone\").IsOverridden();\n// simpler: f is MS.Internal.Xaml.Context.ObjectWriterFrame","typeGuard":"static bool CanClone(XamlFrame f) => f is ObjectWriterFrame;","tryCatchPattern":"try { copy = frame.Clone(); }\ncatch (NotImplementedException) { /* fall back to Reset() reuse or skip cloning */ }","preventionTips":["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"],"tags":["wpf","xaml","not-implemented","abstract-method"],"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-21T21:30:21.729Z"}