{"record":{"id":"9dc32890343233b5","repo":"dotnet/wpf","slug":"sr-format-sr-prefixnotfound-typename-prefix","errorCode":null,"errorMessage":"SR.Format(SR.PrefixNotFound, typeName.Prefix)","messagePattern":"SR\\.Format\\(SR\\.PrefixNotFound, typeName\\.Prefix\\)","errorType":"exception","errorClass":"XamlParseException","httpStatus":null,"severity":"error","filePath":"src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/XamlContext.cs","lineNumber":247,"sourceCode":"        }\n\n        internal XamlType GetXamlType(XamlName typeName)\n        {\n            return GetXamlType(typeName, false);\n        }\n\n        internal XamlType GetXamlType(XamlName typeName, bool returnUnknownTypesOnFailure)\n        {\n            XamlTypeName fullTypeName = GetXamlTypeName(typeName);\n            return GetXamlType(fullTypeName, returnUnknownTypesOnFailure);\n        }\n\n        internal XamlTypeName GetXamlTypeName(XamlName typeName)\n        {\n            string xamlNs = ResolveXamlNameNS(typeName);\n            if (xamlNs is null)\n            {\n                throw new XamlParseException(SR.Format(SR.PrefixNotFound, typeName.Prefix));\n            }\n\n            return new XamlTypeName(xamlNs, typeName.Name);\n        }\n\n        internal XamlType GetXamlType(XamlTypeName typeName)\n        {\n            return GetXamlType(typeName, false, false);\n        }\n\n        internal XamlType GetXamlType(XamlTypeName typeName, bool returnUnknownTypesOnFailure)\n        {\n            return GetXamlType(typeName, returnUnknownTypesOnFailure, false);\n        }\n\n        internal XamlType GetXamlType(XamlTypeName typeName, bool returnUnknownTypesOnFailure,\n            bool skipVisibilityCheck)\n        {","sourceCodeStart":229,"sourceCodeEnd":265,"githubUrl":"https://github.com/dotnet/wpf/blob/81131a70a4c573cd62748a5c36908fc4d662daa9/src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/XamlContext.cs#L229-L265","documentation":"GetXamlTypeName resolves a XamlName's prefix to a XAML namespace before constructing a XamlTypeName; if ResolveXamlNameNS returns null the prefix is unknown and XamlParseException(PrefixNotFound, prefix) is thrown. Called by fullTypeName during type-name resolution.","triggerScenarios":"Resolving a type reference such as x:Type extensions={x:Static ...} or MarkupExtension type references where the prefix in the type name has no matching xmlns declaration in scope.","commonSituations":"Typos in prefixes on type usages (e.g. {local:Converter} without xmlns:local); missing xmlns on the root element; XAML moved between files losing namespace scope; dynamic XAML strings generated without emitted xmlns declarations.","solutions":["Declare the prefix: add xmlns:local=\"clr-namespace:...;assembly=...\" to the root element.","Fix the prefix in the type reference to match a declared namespace.","Ensure generated/dynamic XAML emits all needed xmlns declarations.","Catch XamlParseException, parse the prefix from the message, and validate all prefixes against declared namespaces before parsing."],"exampleFix":"// before\n<Button Style=\"{styles:MyStyle}\"/> <!-- styles undeclared -->\n// after\n<Window xmlns:styles=\"clr-namespace:App.Styles;assembly=App\" ...>\n  <Button Style=\"{styles:MyStyle}\"/>\n</Window>","handlingStrategy":"validation","validationCode":"// validate every prefix in type references is declared before resolution\nbool prefixDeclared = root.Attributes().Any(a => a.IsNamespaceDeclaration && a.Name.LocalName == typeName.Prefix);\nif (!prefixDeclared) throw new XamlParseException($\"Undeclared prefix '{typeName.Prefix}' in type reference\");","typeGuard":"bool CanResolvePrefix(XmlNamespaceManager nsMgr, string prefix) => prefix == \"\" || nsMgr.LookupNamespace(prefix) != null;","tryCatchPattern":"try { var tn = helper.FullTypeName(name); }\ncatch (XamlParseException ex) when (ex.Message.Contains(\"prefix\")) { // undeclared prefix on type reference\n  throw new FormatException(\"Add xmlns declaration for prefix: \" + ex.Message, ex); }","preventionTips":["Declare all xmlns prefixes on the root element","Generate dynamic XAML with explicit xmlns emissions","Validate prefixes with XmlNamespaceManager before parsing type names"],"tags":["wpf","system-xaml","xaml-parse","xml-namespace","undeclared-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"}