{"record":{"id":"ac3e5ff640cf4480","repo":"dotnet/wpf","slug":"sr-image-inplacemetadatanocopy","errorCode":null,"errorMessage":"SR.Image_InplaceMetadataNoCopy","messagePattern":"SR\\.Image_InplaceMetadataNoCopy","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/InplaceBitmapMetadataWriter.cs","lineNumber":133,"sourceCode":"\n        #region Freezable\n\n        /// <summary>\n        ///     Shadows inherited Copy() with a strongly typed\n        ///     version for convenience.\n        /// </summary>\n        public new InPlaceBitmapMetadataWriter Clone()\n        {\n            return (InPlaceBitmapMetadataWriter)base.Clone();\n        }\n\n        /// <summary>\n        /// Implementation of <see cref=\"System.Windows.Freezable.CreateInstanceCore\">Freezable.CreateInstanceCore</see>.\n        /// </summary>\n        /// <returns>The new Freezable.</returns>\n        protected override Freezable CreateInstanceCore()\n        {\n            throw new InvalidOperationException(SR.Image_InplaceMetadataNoCopy);\n        }\n\n        /// <summary>\n        /// Implementation of <see cref=\"System.Windows.Freezable.CloneCore(Freezable)\">Freezable.CloneCore</see>.\n        /// </summary>\n        protected override void CloneCore(Freezable sourceFreezable)\n        {\n            throw new InvalidOperationException(SR.Image_InplaceMetadataNoCopy);\n        }\n\n        /// <summary>\n        /// Implementation of <see cref=\"System.Windows.Freezable.CloneCurrentValueCore(Freezable)\">Freezable.CloneCurrentValueCore</see>.\n        /// </summary>\n        protected override void CloneCurrentValueCore(Freezable sourceFreezable)\n        {\n            throw new InvalidOperationException(SR.Image_InplaceMetadataNoCopy);\n        }\n","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/Media/Imaging/InplaceBitmapMetadataWriter.cs#L115-L151","documentation":"InplaceBitmapMetadataWriter writes metadata in place inside an existing image file/frame and cannot be duplicated. Freezable.CreateInstanceCore is part of Freezable's clone machinery, which would require copying the writer, so WPF throws this InvalidOperationException by design.","triggerScenarios":"Any code path that invokes Freezable.CreateInstanceCore on an InplaceBitmapMetadataWriter — e.g. calling Clone(), CloneCurrentValue(), GetAsFrozen() or other Freezable copy operations that internally default-construct a new instance.","commonSituations":"Developers treating the metadata writer like a normal Freezable bitmap object and calling Clone() to snapshot metadata before editing; WPF data-binding or animation infrastructure that automatically clones Freezable values.","solutions":["Do not clone InplaceBitmapMetadataWriter; perform metadata edits directly on the single in-place instance.","To keep a copy of metadata, read the values (e.g. via GetQuery) and store them yourself, then create a new BitmapMetadata object for the copy.","Use BitmapMetadata obtained from a frame (frame.Metadata) for non-inplace scenarios instead of the inplace writer."],"exampleFix":null,"handlingStrategy":"type-guard","validationCode":"if (freezable is InplaceBitmapMetadataWriter) { /* do not clone; edit in place */ }","typeGuard":"static bool IsClonableMetadata(Freezable f) => f is not InplaceBitmapMetadataWriter;","tryCatchPattern":"try { var copy = f.Clone(); } catch (InvalidOperationException ex) { /* fall back to reading GetQuery values */ }","preventionTips":["Never call Clone/GetAsFrozen family methods on InplaceBitmapMetadataWriter.","Exclude in-place writers from generic Freezable caching/cloning helpers.","Snapshot metadata by copying queried values, not by cloning the writer."],"tags":["wpf","imaging","metadata","unsupported-operation"],"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"}