dotnet/wpf · error · InvalidOperationException
SR.PropertyMustHaveValue (formatted with "Uri", type name)
Error message
SR.PropertyMustHaveValue (formatted with "Uri", type name)
What it means
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.
Solutions
- Set both Prefix and Uri before EndInit().
- Prefer the two-argument constructor XmlNamespaceMapping(prefix, uri).
- Validate uri != null before entering BeginInit/EndInit.
Example fix
// before
mapping.BeginInit();
mapping.Prefix = "atom";
mapping.EndInit(); // throws
// after
mapping.BeginInit();
mapping.Prefix = "atom";
mapping.Uri = new Uri("http://www.w3.org/2005/Atom");
mapping.EndInit(); Defensive patterns
Strategy: validation
Validate before calling
if (uri == null) throw new ArgumentException("Uri required before EndInit", nameof(uri));
((ISupportInitialize)mapping).BeginInit();
mapping.Prefix = prefix;
mapping.Uri = uri;
((ISupportInitialize)mapping).EndInit(); Try / catch
try { ((ISupportInitialize)mapping).EndInit(); }
catch (InvalidOperationException ex) { log.Error("Mapping incomplete: " + ex.Message, ex); } Prevention
- 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.
When it happens
Trigger: Calling EndInit() after setting only Prefix (Uri left null), or completing initialization without setting either property.
Common situations: Forgetting the Uri when building mappings in code; a Uri variable that is null due to a failed parse earlier in the setup code.
Understand the failure class
Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.
Related errors
- SR.PropertyMustHaveValue (formatted with "Prefix", type…
- SR.RequiresXmlNamespaceMappingUri
- " }} " element found. Expected fixed page element ( }} ).
- Bracket characters cannot be alpha-numeric or whitespace.
- Bracket characters cannot be one of the following: '=' …
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/2f1c565a6deef190.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Data/XmlNamespaceMapping.cs:141
#region ISupportInitialize
/// <summary>Begin Initialization</summary>
void ISupportInitialize.BeginInit()
{
_initializing = true;
}
/// <summary>End Initialization, verify that internal state is consistent</summary>
void ISupportInitialize.EndInit()
{
if (_prefix == null)
{
throw new InvalidOperationException(SR.Format(SR.PropertyMustHaveValue, "Prefix", this.GetType().Name));
}
if (_uri == null)
{
throw new InvalidOperationException(SR.Format(SR.PropertyMustHaveValue, "Uri", this.GetType().Name));
}
_initializing = false;
}
#endregion ISupportInitialize
private string _prefix;
private Uri _uri;
private bool _initializing;
}
}
View on GitHub (pinned to 81131a70a4)