dotnet/wpf · error
SR.Format(SR.ParserPrefixNSProperty, nsPrefix, nameString)
Error message
SR.Format(SR.ParserPrefixNSProperty, nsPrefix, nameString)
What it means
RoutedEventConverter.ExtractNamespaceString parses a prefixed XAML name (e.g. 'ns:MyEvent'); after extracting the prefix it looks the prefix up in the parser context's XmlnsDictionary, and throws ArgumentException when the prefix has no corresponding xmlns mapping. Without the mapping the event reference cannot be resolved to a namespace URI.
Solutions
- Declare the missing xmlns prefix mapping at the root element of the XAML file
- Fix typos in the namespace prefix in the attribute/element name
- Verify the referenced assembly is referenced and the clr-namespace/assembly values are correct
Example fix
// before <Window> <Button Click="custom:MyHandler" /> </Window> // after <Window xmlns:custom="clr-namespace:MyApp.Events;assembly=MyApp"> <Button Click="custom:MyHandler" /> </Window>
Defensive patterns
Strategy: validation
Validate before calling
// validate prefixes before parsing
if (!parserContext.XmlnsDictionary.ContainsKey(nsPrefix))
throw new ArgumentException($"Undeclared xmlns prefix '{nsPrefix}' in '{nameString}'"); Try / catch
try { var evt = (RoutedEvent)TypeDescriptor.GetConverter(typeof(RoutedEvent)).ConvertFromString(name); }
catch (ArgumentException ex) { /* check xmlns declarations in the XAML */ } Prevention
- Always declare xmlns prefixes used in element/attribute names at the document root
- Lint XAML for undeclared prefixes before runtime load
- Keep clr-namespace and assembly names in sync with project references
When it happens
Trigger: Converting a string like 'x:Static' or 'custom:MyEvent' to a RoutedEvent during XAML deserialization when the prefix was never declared via xmlns in the XAML, or the parserContext XmlnsDictionary lacks the prefix entry.
Common situations: XAML that references a custom control library's routed events without declaring xmlns:custom="clr-namespace:...;assembly=..."; typos in prefix names; copy-pasted XAML missing namespace declarations.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- ArgumentNullException(nameof(newNamespace))
- ArgumentNullException(nameof(oldNamespace))
- SR.CanOnlyHaveOneChild
- SR.CanOnlyHaveOneChild
- SR.DuplicatedCompatibleUri
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/2d045e2d7bab5f3b.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/RoutedEventConverter.cs:165
// the need to duplicate code. See task #18279
private string ExtractNamespaceString(ref string nameString, ParserContext parserContext)
{
// The colon is what we look for to determine if there's a namespace prefix specifier.
int nsIndex = nameString.IndexOf(':');
string nsPrefix = string.Empty;
if (nsIndex != -1)
{
// Found a namespace prefix separator, so create replacement propertyName.
// String processing - split "foons" from "BarClass.BazProp"
nsPrefix = nameString.Substring(0, nsIndex);
nameString = nameString.Substring(nsIndex + 1);
}
// Find the namespace, even if its the default one
string namespaceURI = parserContext.XmlnsDictionary[nsPrefix];
if (namespaceURI == null)
{
throw new ArgumentException(SR.Format(SR.ParserPrefixNSProperty, nsPrefix, nameString));
}
return namespaceURI;
}
}
}
View on GitHub (pinned to 81131a70a4)