{"record":{"id":"8c3067d530101f22","repo":"dotnet/wpf","slug":"sr-propertyisimmutable-formatted-with-prefix-type-name","errorCode":null,"errorMessage":"SR.PropertyIsImmutable (formatted with \"Prefix\", type name)","messagePattern":"SR\\.PropertyIsImmutable \\(formatted with \"Prefix\", type name\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/XmlNamespaceMapping.cs","lineNumber":48,"sourceCode":"        /// </summary>\n        public XmlNamespaceMapping(string prefix, Uri uri)\n        {\n            _prefix = prefix;\n            _uri = uri;\n        }\n\n        /// <summary>\n        /// The prefix to be used for this Namespace\n        /// </summary>\n        public string Prefix\n        {\n            get { return _prefix; }\n            set\n            {\n                if (!_initializing)\n                    throw new InvalidOperationException(SR.Format(SR.PropertyIsInitializeOnly, \"Prefix\", this.GetType().Name));\n                if (_prefix != null && _prefix != value)\n                    throw new InvalidOperationException(SR.Format(SR.PropertyIsImmutable, \"Prefix\", this.GetType().Name));\n\n                _prefix = value;\n            }\n        }\n\n        /// <summary>\n        /// The Uri to be used for this Namespace,\n        /// can be declared as an attribute or as the\n        /// TextContent of the XmlNamespaceMapping markup tag\n        /// </summary>\n        public Uri Uri\n        {\n            get { return _uri; }\n            set\n            {\n                if (!_initializing)\n                    throw new InvalidOperationException(SR.Format(SR.PropertyIsInitializeOnly, \"Uri\", this.GetType().Name));\n                if (_uri != null && _uri != value)","sourceCodeStart":30,"sourceCodeEnd":66,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/XmlNamespaceMapping.cs#L30-L66","documentation":"Once XmlNamespaceMapping.Prefix has been set (during initialization), it cannot be changed: a second assignment with a different value throws an InvalidOperationException with SR.PropertyIsImmutable. This keeps the mapping stable while the XML data binding is active.","triggerScenarios":"Inside a BeginInit scope, assigning Prefix a value when _prefix is already non-null and different from the new value (e.g. reusing and mutating a parsed mapping object).","commonSituations":"Reusing a single XmlNamespaceMapping instance across several XmlNamespaceMappingCollection entries with different prefixes; attempting to hot-swap the prefix on a live binding.","solutions":["Create a new XmlNamespaceMapping instance instead of mutating an existing one.","Ensure the same Prefix value is assigned only once per instance.","If the prefix must change, rebuild the mapping and re-add it to the collection."],"exampleFix":"// before\nmapping.Prefix = \"rss\";\nmapping.Prefix = \"atom\"; // throws\n// after\nvar atomMapping = new XmlNamespaceMapping();\n((ISupportInitialize)atomMapping).BeginInit();\natomMapping.Prefix = \"atom\";\natomMapping.Uri = new Uri(\"http://www.w3.org/2005/Atom\");\n((ISupportInitialize)atomMapping).EndInit();","handlingStrategy":"validation","validationCode":"if (existing.Prefix != null && existing.Prefix != newPrefix)\n    throw new InvalidOperationException(\"Prefix is immutable; create a new mapping\");","typeGuard":null,"tryCatchPattern":"try { mapping.Prefix = newPrefix; }\ncatch (InvalidOperationException ex) { log.Error(\"Prefix already set; create a new XmlNamespaceMapping\", ex); }","preventionTips":["Treat Prefix as write-once; never reuse mapping instances across namespaces.","Create a fresh XmlNamespaceMapping per prefix/uri pair.","Centralize mapping creation in one helper method."],"tags":["wpf","xml","immutability","initialization"],"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"}