{"record":{"id":"2f1c565a6deef190","repo":"dotnet/wpf","slug":"sr-propertymusthavevalue-formatted-with-uri-type-name","errorCode":null,"errorMessage":"SR.PropertyMustHaveValue (formatted with \"Uri\", type name)","messagePattern":"SR\\.PropertyMustHaveValue \\(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":141,"sourceCode":"\n#region ISupportInitialize\n\n        /// <summary>Begin Initialization</summary>\n        void ISupportInitialize.BeginInit()\n        {\n            _initializing = true;\n        }\n\n        /// <summary>End Initialization, verify that internal state is consistent</summary>\n        void ISupportInitialize.EndInit()\n        {\n            if (_prefix == null)\n            {\n                throw new InvalidOperationException(SR.Format(SR.PropertyMustHaveValue, \"Prefix\", this.GetType().Name));\n            }\n            if (_uri == null)\n            {\n                throw new InvalidOperationException(SR.Format(SR.PropertyMustHaveValue, \"Uri\", this.GetType().Name));\n            }\n\n            _initializing = false;\n        }\n\n#endregion ISupportInitialize\n\n        private string _prefix;\n        private Uri _uri;\n        private bool _initializing;\n    }\n}\n","sourceCodeStart":123,"sourceCodeEnd":154,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/XmlNamespaceMapping.cs#L123-L154","documentation":"EndInit also requires Uri: if _uri is null when the initialization window closes, XmlNamespaceMapping throws an InvalidOperationException with SR.PropertyMustHaveValue formatted with \"Uri\". A mapping must fully specify prefix and namespace URI to be usable.","triggerScenarios":"Calling EndInit() after setting only Prefix (Uri left null), or completing initialization without setting either property.","commonSituations":"Forgetting the Uri when building mappings in code; a Uri variable that is null due to a failed parse earlier in the setup code.","solutions":["Set both Prefix and Uri before EndInit().","Prefer the two-argument constructor XmlNamespaceMapping(prefix, uri).","Validate uri != null before entering BeginInit/EndInit."],"exampleFix":"// before\nmapping.BeginInit();\nmapping.Prefix = \"atom\";\nmapping.EndInit(); // throws\n// after\nmapping.BeginInit();\nmapping.Prefix = \"atom\";\nmapping.Uri = new Uri(\"http://www.w3.org/2005/Atom\");\nmapping.EndInit();","handlingStrategy":"validation","validationCode":"if (uri == null) throw new ArgumentException(\"Uri required before EndInit\", nameof(uri));\n((ISupportInitialize)mapping).BeginInit();\nmapping.Prefix = prefix;\nmapping.Uri = uri;\n((ISupportInitialize)mapping).EndInit();","typeGuard":null,"tryCatchPattern":"try { ((ISupportInitialize)mapping).EndInit(); }\ncatch (InvalidOperationException ex) { log.Error(\"Mapping incomplete: \" + ex.Message, ex); }","preventionTips":["Validate uri != null before BeginInit/EndInit.","Prefer constructor initialization so both fields are always set.","Guard against earlier failures that leave the uri variable null."],"tags":["wpf","xml","validation","missing-value"],"backgroundTag":"missing-required-argument","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"}