{"record":{"id":"d9d3517580e7557a","repo":"dotnet/wpf","slug":"sr-typemetadatacannotchangeafteruse","errorCode":null,"errorMessage":"SR.TypeMetadataCannotChangeAfterUse","messagePattern":"SR\\.TypeMetadataCannotChangeAfterUse","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIPropertyMetadata.cs","lineNumber":106,"sourceCode":"\n        /// <summary>\n        /// Set this to true for a property for which animation should be\n        /// prohibited. This should not be set unless there are very strong\n        /// technical reasons why a property can not be animated. In the\n        /// vast majority of cases, a property that can not be properly\n        /// animated means that the property implementation contains a bug.\n        /// </summary>\n        public bool IsAnimationProhibited\n        {\n            get\n            {\n                return ReadFlag(MetadataFlags.UI_IsAnimationProhibitedID);\n            }\n            set\n            {\n                if (Sealed)\n                {\n                    throw new InvalidOperationException(SR.TypeMetadataCannotChangeAfterUse);\n                }\n\n                WriteFlag(MetadataFlags.UI_IsAnimationProhibitedID, value);\n            }\n        }\n    }\n}\n\n","sourceCodeStart":88,"sourceCodeEnd":115,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationCore/System/Windows/UIPropertyMetadata.cs#L88-L115","documentation":"UIPropertyMetadata.IsAnimationProhibited (and other metadata settings) can only be changed while the metadata instance is unsealed. Metadata is sealed once attached to a DependencyProperty via OverrideMetadata/AddOwner, after which any setter throws InvalidOperationException(SR.TypeMetadataCannotChangeAfterUse).","triggerScenarios":"Setting IsAnimationProhibited on a metadata instance that was already passed to OverrideMetadata or otherwise used to register/override a property.","commonSituations":"Tweaking shared metadata instances after framework startup; mutating a base class's metadata instance instead of creating a new one; changing metadata in response to runtime conditions.","solutions":["Create a new UIPropertyMetadata instance and call OverrideMetadata again instead of mutating the sealed one","Set IsAnimationProhibited before the metadata is attached to a property (at type-initialization time)","Check the Sealed property before writing metadata flags"],"exampleFix":"// before\nmyMetadata.IsAnimationProhibited = true; // metadata already sealed\n// after\nvar newMetadata = new UIPropertyMetadata(myMetadata.DefaultValue) { IsAnimationProhibited = true };\nMyProperty.OverrideMetadata(typeof(MyControl), newMetadata);","handlingStrategy":"validation","validationCode":"if (!myMetadata.Sealed) { myMetadata.IsAnimationProhibited = value; }\nelse { /* create a fresh UIPropertyMetadata and OverrideMetadata */ }","typeGuard":"static bool CanMutate(UIPropertyMetadata m) => !m.Sealed;","tryCatchPattern":"try { metadata.IsAnimationProhibited = true; }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"metadata\")) { log.Error(\"Metadata already sealed; create a new instance\", ex); }","preventionTips":["Configure metadata exclusively in static constructors / before first OverrideMetadata","Treat metadata instances as immutable after registration; clone instead of mutating","Never mutate base-class metadata instances; always create your own"],"tags":["wpf","dependency-properties","metadata","immutability"],"backgroundTag":"invalid-state-transition","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"}