dotnet/wpf · error · TypeNameParserException

SR.PrefixNotFound

Error message

SR.PrefixNotFound

What it means

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).

Solutions

  1. Add or correct the xmlns declaration for the missing prefix in the XAML document
  2. Ensure the assembly/namespace is registered with the XamlSchemaContext (XmlnsDefinition attributes or AddAssembly call)
  3. Fix the prefix spelling in the type string passed to the parser
  4. Wrap XamlTypeName.Parse in try-catch on TypeNameParserException and surface a friendly message

Example fix

// before
<x:Object xmlns="clr-unknown"> <local:Widget/> </x:Object>
// after
<x:Object xmlns:local="clr-namespace:MyApp.Controls"> <local:Widget/> </x:Object>
Defensive patterns

Strategy: validation

Validate before calling

// before parsing: ensure every prefix in the type string is registered
bool IsPrefixKnown(string typeName, Func<string,string> resolver)
{
    int i = typeName.IndexOf(':');
    if (i < 0) return true; // default namespace
    return resolver(typeName.Substring(0, i)) != null;
}

Try / catch

try { var t = XamlTypeName.Parse(input, resolver, out var err); }
catch (TypeNameParserException ex) { /* report prefix not found; inspect ex.Message for the prefix */ }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

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


AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14). Data as JSON: /api/errors/010c9d99fa92009e. Report an issue: GitHub.

Appendix: source

Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Parser/GenericTypeNameParser.cs:270

            throw new TypeNameParserException(SR.Format(SR.InvalidCharInTypeName, _scanner.ErrorCurrentChar, _inputText));
        }

        private void StartStack()
        {
            _stack = new Stack<TypeNameFrame>();
            TypeNameFrame frame;
            frame = new TypeNameFrame();
            _stack.Push(frame);
        }

        private void Callout_FoundName(string prefix, string name)
        {
            TypeNameFrame frame = new TypeNameFrame
            {
                Name = name
            };
            string ns = _prefixResolver(prefix);
            frame.Namespace = ns ?? throw new TypeNameParserException(SR.Format(SR.PrefixNotFound, prefix));
            _stack.Push(frame);
        }

        private void Callout_EndOfType()
        {
            TypeNameFrame frame = _stack.Pop();
            XamlTypeName typeName = new XamlTypeName(frame.Namespace, frame.Name, frame.TypeArgs);

            frame = _stack.Peek();
            if (frame.TypeArgs is null)
            {
                frame.AllocateTypeArgs();
            }

            frame.TypeArgs.Add(typeName);
        }

        private void Callout_Subscript(string subscript)

View on GitHub (pinned to 81131a70a4)