{"record":{"id":"2d045e2d7bab5f3b","repo":"dotnet/wpf","slug":"sr-format-sr-parserprefixnsproperty-nsprefix-namestring","errorCode":null,"errorMessage":"SR.Format(SR.ParserPrefixNSProperty, nsPrefix, nameString)","messagePattern":"SR\\.Format\\(SR\\.ParserPrefixNSProperty, nsPrefix, nameString\\)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/RoutedEventConverter.cs","lineNumber":165,"sourceCode":"        //  the need to duplicate code.  See task #18279\n        private string ExtractNamespaceString(ref string nameString, ParserContext parserContext)\n        {\n            // The colon is what we look for to determine if there's a namespace prefix specifier.\n            int nsIndex = nameString.IndexOf(':');\n            string nsPrefix = string.Empty;\n            if (nsIndex != -1)\n            {\n                // Found a namespace prefix separator, so create replacement propertyName.\n                // String processing - split \"foons\" from \"BarClass.BazProp\"\n                nsPrefix = nameString.Substring(0, nsIndex);\n                nameString = nameString.Substring(nsIndex + 1);\n            }\n\n            // Find the namespace, even if its the default one\n            string namespaceURI = parserContext.XmlnsDictionary[nsPrefix];\n            if (namespaceURI == null)\n            {\n                throw new ArgumentException(SR.Format(SR.ParserPrefixNSProperty, nsPrefix, nameString));\n            }\n\n            return namespaceURI;\n        }\n    }\n}\n    \n\n","sourceCodeStart":147,"sourceCodeEnd":174,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/Markup/RoutedEventConverter.cs#L147-L174","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\n<Window>\n  <Button Click=\"custom:MyHandler\" />\n</Window>\n// after\n<Window xmlns:custom=\"clr-namespace:MyApp.Events;assembly=MyApp\">\n  <Button Click=\"custom:MyHandler\" />\n</Window>","handlingStrategy":"validation","validationCode":"// validate prefixes before parsing\nif (!parserContext.XmlnsDictionary.ContainsKey(nsPrefix))\n    throw new ArgumentException($\"Undeclared xmlns prefix '{nsPrefix}' in '{nameString}'\");","typeGuard":null,"tryCatchPattern":"try { var evt = (RoutedEvent)TypeDescriptor.GetConverter(typeof(RoutedEvent)).ConvertFromString(name); }\ncatch (ArgumentException ex) { /* check xmlns declarations in the XAML */ }","preventionTips":["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"],"tags":["wpf","xaml","namespace","argument-exception"],"backgroundTag":"resource-not-found","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"}