{"record":{"id":"010c9d99fa92009e","repo":"dotnet/wpf","slug":"sr-prefixnotfound","errorCode":null,"errorMessage":"SR.PrefixNotFound","messagePattern":"SR\\.PrefixNotFound","errorType":"exception","errorClass":"TypeNameParserException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/GenericTypeNameParser.cs","lineNumber":270,"sourceCode":"            throw new TypeNameParserException(SR.Format(SR.InvalidCharInTypeName, _scanner.ErrorCurrentChar, _inputText));\n        }\n\n        private void StartStack()\n        {\n            _stack = new Stack<TypeNameFrame>();\n            TypeNameFrame frame;\n            frame = new TypeNameFrame();\n            _stack.Push(frame);\n        }\n\n        private void Callout_FoundName(string prefix, string name)\n        {\n            TypeNameFrame frame = new TypeNameFrame\n            {\n                Name = name\n            };\n            string ns = _prefixResolver(prefix);\n            frame.Namespace = ns ?? throw new TypeNameParserException(SR.Format(SR.PrefixNotFound, prefix));\n            _stack.Push(frame);\n        }\n\n        private void Callout_EndOfType()\n        {\n            TypeNameFrame frame = _stack.Pop();\n            XamlTypeName typeName = new XamlTypeName(frame.Namespace, frame.Name, frame.TypeArgs);\n\n            frame = _stack.Peek();\n            if (frame.TypeArgs is null)\n            {\n                frame.AllocateTypeArgs();\n            }\n\n            frame.TypeArgs.Add(typeName);\n        }\n\n        private void Callout_Subscript(string subscript)","sourceCodeStart":252,"sourceCodeEnd":288,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/GenericTypeNameParser.cs#L252-L288","documentation":"GenericTypeNameParser's Callout_FoundName resolves a namespace prefix via the prefix-resolver callback while parsing a XAML type name string (XamlTypeName.Parse). When the prefix (e.g. 'x' in 'x:String') is not registered in the namespace context, the resolver returns null and the parser throws TypeNameParserException(SR.PrefixNotFound, prefix).","triggerScenarios":"Calling XamlTypeName.Parse / XamlType resolution with a type string whose namespace prefix is not registered in the parser's namespace context, e.g. parsing 'foo:Bar' where 'foo' has no xmlns declaration in the schema context.","commonSituations":"Typos in xmlns prefixes, missing xmlns declarations in XAML, referencing types from assemblies whose xmlns mappings were never added to the XamlSchemaContext, copy-pasted markup between projects with different namespaces.","solutions":["Add or correct the xmlns declaration for the missing prefix in the XAML document","Ensure the assembly/namespace is registered with the XamlSchemaContext (XmlnsDefinition attributes or AddAssembly call)","Fix the prefix spelling in the type string passed to the parser","Wrap XamlTypeName.Parse in try-catch on TypeNameParserException and surface a friendly message"],"exampleFix":"// before\n<x:Object xmlns=\"clr-unknown\"> <local:Widget/> </x:Object>\n// after\n<x:Object xmlns:local=\"clr-namespace:MyApp.Controls\"> <local:Widget/> </x:Object>","handlingStrategy":"validation","validationCode":"// before parsing: ensure every prefix in the type string is registered\nbool IsPrefixKnown(string typeName, Func<string,string> resolver)\n{\n    int i = typeName.IndexOf(':');\n    if (i < 0) return true; // default namespace\n    return resolver(typeName.Substring(0, i)) != null;\n}","typeGuard":null,"tryCatchPattern":"try { var t = XamlTypeName.Parse(input, resolver, out var err); }\ncatch (TypeNameParserException ex) { /* report prefix not found; inspect ex.Message for the prefix */ }","preventionTips":["Declare xmlns prefixes at the document root","Keep XmlnsDefinition attributes in your assemblies","Validate prefixes against the schema context in tests"],"tags":["xaml","type-parsing","namespace-prefix"],"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"}