AvaloniaUI/Avalonia · error · InvalidOperationException

Unable to resolve type '{@namespace}:{name}'.

Error message

Unable to resolve type '{@namespace}:{name}'.

What it means

ExpressionNodeFactory.LookupType delegates namespace+name to a caller-supplied typeResolver (typically the XAML namespace/sclr-type resolver). If the resolver is null or returns null for the requested namespace and type name, the type cannot be resolved and InvalidOperationException is thrown. This affects reflection bindings referencing types (ancestor casts, attached-property owners).

Source

Thrown at src/Avalonia.Base/Data/Core/Parsers/ExpressionNodeFactory.cs:143

            Type? type = null;

            if (!string.IsNullOrEmpty(ancestor.TypeName))
            {
                type = LookupType(typeResolver, ancestor.Namespace, ancestor.TypeName);
            }

            return new LogicalAncestorElementNode(type, ancestor.Level);
        }

        private static Type LookupType(
            Func<string?, string, Type?>? typeResolver,
            string? @namespace,
            string? name)
        {
            if (name is null)
                throw new InvalidOperationException($"Unable to resolve unnamed type from namespace '{@namespace}'.");
            return typeResolver?.Invoke(@namespace, name) ??
                throw new InvalidOperationException($"Unable to resolve type '{@namespace}:{name}'.");
        }
    }
}

View on GitHub (pinned to 11c5427268)

Solutions

  1. Add the correct xmlns and assembly reference so the resolver can map the type.
  2. Fix the type name spelling.
  3. For trimming/AOT, ensure the referenced type is rooted/preserved.

Example fix

<!-- before -->
{Binding $ancestor[Foo]}  <!-- Foo not resolvable -->
<!-- after -->
xmlns:ctrl="clr-namespace:MyApp.Controls"
{Binding $ancestor[ctrl:Foo]}
Defensive patterns

Strategy: validation

Validate before calling

// Resolve the type through the same resolver the binding will use, up front:
Type? resolved = typeResolver?.Invoke(@namespace, typeName);
if (resolved is null) { /* fix xmlns/assembly before binding */ }

Prevention

When it happens

Trigger: {Binding $ancestor[UnknownType]}, (UnknownNs:UnknownType), a type from an unreferenced assembly, or a type stripped by trimming so the resolver cannot find it.

Common situations: Missing or wrong xmlns mapping; unreferenced assembly; typo in the type name; AOT/trimming removing the type metadata the resolver depends on.

Related errors


AI-assisted analysis of AvaloniaUI/Avalonia@11c5427268 (2026-08-13). Data as JSON: /api/errors/e8a5454c05b0577b. Report an issue: GitHub.