dotnet/wpf · error · XamlParseException
SR.Format(SR.TypeNotFound, xamlType.GetQualifiedName())
Error message
SR.Format(SR.TypeNotFound, xamlType.GetQualifiedName())
What it means
ObjectWriterContext.ServiceProvider_Resolve resolves a qualified XAML type name to a CLR Type. When neither the direct namespace lookup (ServiceProvider_ResolveXamlType) nor the fallback XamlTypeName.Parse/GetXamlType path yields a type with an underlying CLR type, it throws XamlParseException with SR.TypeNotFound naming the qualified name.
Solutions
- Check the XAML prefix declaration (xmlns:local="clr-namespace:Ns;assembly=Asm") for typos in namespace and assembly name.
- Add a project reference to the assembly containing the type so it is loaded into the AppDomain.
- Verify the type is public and its name (including nested-type '+' syntax) is spelled correctly.
- Confirm the referenced assembly version actually contains the type (rebuild or update package).
Example fix
<!-- before: assembly name wrong or missing --> xmlns:local="clr-namespace:MyApp.Controls;assembly=WrongAsm" <!-- after --> xmlns:local="clr-namespace:MyApp.Controls;assembly=MyApp"
Defensive patterns
Strategy: validation
Validate before calling
// Before loading XAML, verify the referenced type resolves
var asm = Assembly.LoadFrom("MyApp.dll");
if (asm.GetType("MyApp.Controls.MyControl") is null)
throw new InvalidOperationException("Referenced XAML type missing from assembly"); Type guard
static bool TypeResolves(SchemaContext ctx, string prefix, string localName)
=> ctx.GetXamlType(new XamlTypeName(prefix, localName))?.UnderlyingType is not null; Try / catch
try { Resolve(typeName); }
catch (XamlParseException ex) when (ex.Message.Contains("was not found"))
{ /* log qualified name; hint at missing xmlns/assembly reference */ } Prevention
- Always declare xmlns mappings as clr-namespace=...;assembly=... with both parts spelled correctly.
- Add project/package references for every assembly used in XAML.
- Only expose public types to XAML.
- Compile XAML (BAML) rather than runtime-parse where possible — the compiler catches unresolved types.
When it happens
Trigger: XAML markup (or IXamlSchemaContextProvider-based resolution) references a type whose xmlns-prefix mapping does not resolve to a loaded assembly containing that type — e.g. during x:Type resolution or type-converted property values.
Common situations: Missing assembly reference in the project; wrong clr-namespace/assembly spelling in the XAML; type exists in a different assembly version than referenced; type is internal/non-public so it is not visible from the local assembly.
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
- ArgumentNullException(nameof(localName))
- ArgumentNullException(nameof(xmlNamespace))
- SR.Format(SR.MarkupExtensionTypeNameBad, _typeName)
- throw new ArgumentNullException( nameof(element));
- throw new ArgumentNullException( nameof(typeName));
AI-assisted analysis of dotnet/wpf@81131a70a4 (2026-09-14).
Data as JSON: /api/errors/112e126395608345.
Report an issue: GitHub.
Appendix: source
Thrown at src/Microsoft.DotNet.Wpf/src/System.Xaml/System/Xaml/Context/ObjectWriterContext.cs:161
}
#region ServiceProvider Interfaces
// This class doesn't implement the IServiceProvider. That is done
// with worker classes ValueConverterContext or MarkupConverterContext.
// The worker class implements IServiceProvider but uses the real
// context for the implementation of the actual services.
internal Type ServiceProvider_Resolve(string qName)
{
// As soon as we have the necessary setting on ObjectWriter, we need to start passing
// the local assembly into the context; currently, this will only return publics.
XamlType xamlType = ServiceProvider_ResolveXamlType(qName);
if (xamlType is null || xamlType.UnderlyingType is null)
{
XamlTypeName name = XamlTypeName.Parse(qName, _serviceProviderContext);
xamlType = GetXamlType(name, true, true);
throw new XamlParseException(SR.Format(SR.TypeNotFound, xamlType.GetQualifiedName()));
}
return xamlType.UnderlyingType;
}
internal XamlType ServiceProvider_ResolveXamlType(string qName)
{
return ResolveXamlType(qName, true);
}
internal AmbientPropertyValue ServiceProvider_GetFirstAmbientValue(IEnumerable<XamlType> ceilingTypes, XamlMember[] properties)
{
List<AmbientPropertyValue> valueList = FindAmbientValues(ceilingTypes, searchLiveStackOnly: false, types: null, properties, true);
return (valueList.Count == 0) ? null : valueList[0];
}
internal object ServiceProvider_GetFirstAmbientValue(XamlType[] types)
{View on GitHub (pinned to 81131a70a4)