{"record":{"id":"e56faed53a88d430","repo":"dotnet/wpf","slug":"sr-propertymusthavevalue-formatted-with-prefix-type-name","errorCode":null,"errorMessage":"SR.PropertyMustHaveValue (formatted with \"Prefix\", type name)","messagePattern":"SR\\.PropertyMustHaveValue \\(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":137,"sourceCode":"                return unchecked(hash + _uri.GetHashCode());\n            else\n                return hash;\n        }\n\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":119,"sourceCodeEnd":154,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/XmlNamespaceMapping.cs#L119-L154","documentation":"XmlNamespaceMapping's ISupportInitialize.EndInit validates that Prefix was actually set. If _prefix is still null when initialization finishes, it throws an InvalidOperationException stating the property must have a value. A mapping without a Prefix is meaningless for XML namespace resolution.","triggerScenarios":"Calling EndInit() after setting only Uri (Prefix left null), or calling EndInit() without ever setting either property.","commonSituations":"Partial programmatic initialization — forgetting one of the two required properties; conditional code paths that skip the Prefix assignment.","solutions":["Set both Prefix and Uri before calling EndInit().","Use the (string prefix, Uri uri) constructor so both are always supplied.","Add a null check on mapping values before the EndInit call."],"exampleFix":"// before\nmapping.BeginInit();\nmapping.Uri = nsUri;\nmapping.EndInit(); // throws\n// after\nmapping.BeginInit();\nmapping.Prefix = \"atom\";\nmapping.Uri = nsUri;\nmapping.EndInit();","handlingStrategy":"validation","validationCode":"if (string.IsNullOrEmpty(prefix)) throw new ArgumentException(\"Prefix required before EndInit\", nameof(prefix));\n((ISupportInitialize)mapping).BeginInit();\nmapping.Prefix = prefix;\n((ISupportInitialize)mapping).EndInit();","typeGuard":null,"tryCatchPattern":"try { ((ISupportInitialize)mapping).EndInit(); }\ncatch (InvalidOperationException ex) { log.Error(\"Mapping incomplete: \" + ex.Message, ex); }","preventionTips":["Always set both Prefix and Uri before EndInit.","Use the two-argument constructor to avoid partial initialization.","Review code paths that conditionally skip property assignment."],"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"}