{"record":{"id":"f0d2ab539d191b52","repo":"dotnet/wpf","slug":"sr-format-sr-parserprefixnsproperty-nsprefix-name","errorCode":null,"errorMessage":"SR.Format(SR.ParserPrefixNSProperty, nsPrefix, name)","messagePattern":"SR\\.Format\\(SR\\.ParserPrefixNSProperty, nsPrefix, name\\)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/PropertyPath.cs","lineNumber":839,"sourceCode":"            {\n                // Find the namespace prefix\n                string nsPrefix;\n                int nsIndex = name.IndexOf(':');\n                if (nsIndex == -1)\n                    nsPrefix = string.Empty;\n                else\n                {\n                    // Found a namespace prefix separator, so create replacement _pathString.\n                    // String processing - split \"foons\" from \"BarClass.BazProp\"\n                    nsPrefix = name.Substring(0, nsIndex).TrimEnd();\n                    name = name.Substring(nsIndex + 1).TrimStart();\n                }\n\n                // Find the namespace URI, 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, name));\n                }\n\n                TypeAndSerializer typeAndSerializer = parserContext.XamlTypeMapper.GetTypeOnly(namespaceURI, name);\n\n                return typeAndSerializer?.ObjectType;\n            }\n\n            else\n            {\n                if (context is IServiceProvider)\n                {\n\n                    IXamlTypeResolver xtr = (context as IServiceProvider).GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver;\n\n                    if (xtr != null)\n                    {\n                        return xtr.Resolve(name);\n                    }","sourceCodeStart":821,"sourceCodeEnd":857,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/PresentationFramework/System/Windows/PropertyPath.cs#L821-L857","documentation":"GetTypeFromName throws this ArgumentException when a qualified type name 'prefix:TypeName' in the property path uses an XML namespace prefix that is not present in ParserContext.XmlnsDictionary. Since no namespace URI can be found for the prefix, the type cannot be looked up via the XamlTypeMapper and path resolution fails.","triggerScenarios":"Path '(local:MyClass.MyProp)' where XmlnsDictionary has no 'local' entry; using a prefix defined in the XAML document but not propagated into the manually constructed ParserContext; typo in the prefix before the colon.","commonSituations":"Programmatically creating Binding paths with a ParserContext while forgetting to copy xmlns mappings from the XAML; custom clr-namespace prefixes lost when paths are evaluated outside XAML parsing; renamed prefixes after refactoring XAML files.","solutions":["Add the missing prefix to ParserContext.XmlnsDictionary, e.g. ctx.XmlnsDictionary[\"local\"] = \"clr-namespace:MyNs;assembly=MyAssembly\"","Use a prefix that already exists in XmlnsDictionary (inspect its keys) and rewrite the path accordingly","Remove the prefix and reference a type resolvable via the default namespace if applicable","When building contexts in code, replicate all xmlns declarations from the source XAML before path resolution"],"exampleFix":"// before\nvar ctx = new ParserContext();\nvar path = new PropertyPath(\"(local:MyClass.MyProp)\", ctx); // throws\n// after\nvar ctx = new ParserContext();\nctx.XmlnsDictionary[\"local\"] = \"clr-namespace:MyApp.Classes;assembly=MyApp\";\nvar path = new PropertyPath(\"(local:MyClass.MyProp)\", ctx);","handlingStrategy":"validation","validationCode":"bool prefixRegistered = parserContext.XmlnsDictionary.Contains(\"local\");\n// register if missing:\nif (!prefixRegistered) parserContext.XmlnsDictionary[\"local\"] = \"clr-namespace:MyApp;assembly=MyApp\";","typeGuard":"bool PrefixResolvable(string qualifiedName, ParserContext ctx) =>\n    !qualifiedName.Contains(':') || ctx.XmlnsDictionary.Contains(qualifiedName.Split(':')[0]);","tryCatchPattern":"try { var t = GetTypeFromName(qualifiedName, parserContext); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"namespace\") || ex.Message.Contains(\"prefix\")) { /* add xmlns mapping */ }","preventionTips":["Copy all xmlns declarations from XAML into any programmatically built ParserContext","Centralize prefix registration so paths and contexts stay in sync","Check XmlnsDictionary keys before using prefixed names in paths"],"tags":["wpf","binding","property-path","xmlns","parser-context"],"backgroundTag":"invalid-identifier-format","analyzedSha":"81131a70a4c573cd62748a5c36908fc4d662daa9","analyzedAt":"2026-09-14T10:12:48.479Z","contentChangedAt":"2026-09-14T10:12:48.479Z","schemaVersion":2},"datasetVersion":"2026-09-22T01:17:13.364Z"}