{"record":{"id":"efd8d94173d15e26","repo":"dotnet/wpf","slug":"sr-propertyisimmutable-formatted-with-uri-type-name","errorCode":null,"errorMessage":"SR.PropertyIsImmutable (formatted with \"Uri\", type name)","messagePattern":"SR\\.PropertyIsImmutable \\(formatted with \"Uri\", type name\\)","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/XmlNamespaceMapping.cs","lineNumber":67,"sourceCode":"\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)\n                    throw new InvalidOperationException(SR.Format(SR.PropertyIsImmutable, \"Uri\", this.GetType().Name));\n\n                _uri = value;\n            }\n        }\n\n        /// <summary>\n        /// Equality comparison by value\n        /// </summary>\n        public override bool Equals(object obj)\n        {\n            return (this == (obj as XmlNamespaceMapping));  // call the == operator override\n        }\n\n        /// <summary>\n        /// Equality comparison by value\n        /// </summary>\n        public static bool operator == (XmlNamespaceMapping mappingA, XmlNamespaceMapping mappingB)\n        {","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/XmlNamespaceMapping.cs#L49-L85","documentation":"Once XmlNamespaceMapping.Uri has a value, reassigning it during a later initialization pass with a different URI throws an InvalidOperationException with SR.PropertyIsImmutable. Prefix and Uri are both write-once to keep namespace mappings consistent.","triggerScenarios":"Within BeginInit scope, setting Uri when _uri is already non-null and different (reusing a mapping instance for a second namespace).","commonSituations":"Sharing one mapping object across multiple collections/entries; trying to retarget an existing mapping to a new namespace URI.","solutions":["Instantiate a fresh XmlNamespaceMapping for each prefix/uri pair.","Assign Uri exactly once per instance.","Remove the old mapping from the XmlNamespaceMappingCollection and add a new one instead of mutating."],"exampleFix":"// before\nmapping.Uri = new Uri(\"http://old.namespace\");\nmapping.Uri = new Uri(\"http://new.namespace\"); // throws\n// after\ncollection.Remove(mapping);\nvar newMapping = new XmlNamespaceMapping(\"ns\", new Uri(\"http://new.namespace\"));\ncollection.Add(newMapping);","handlingStrategy":"validation","validationCode":"if (existing.Uri != null && existing.Uri != newUri)\n    throw new InvalidOperationException(\"Uri is immutable; create a new mapping\");","typeGuard":null,"tryCatchPattern":"try { mapping.Uri = newUri; }\ncatch (InvalidOperationException ex) { log.Error(\"Uri already set; create a new XmlNamespaceMapping\", ex); }","preventionTips":["Assign Uri exactly once per instance.","Remove-and-readd a new mapping to change namespaces.","Keep mapping objects immutable by convention in your codebase."],"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-21T21:30:21.729Z"}