{"record":{"id":"e8a5454c05b0577b","repo":"AvaloniaUI/Avalonia","slug":"unable-to-resolve-type-namespace-name","errorCode":null,"errorMessage":"Unable to resolve type '{@namespace}:{name}'.","messagePattern":"Unable to resolve type '(.+?):(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Avalonia.Base/Data/Core/Parsers/ExpressionNodeFactory.cs","lineNumber":143,"sourceCode":"            Type? type = null;\n\n            if (!string.IsNullOrEmpty(ancestor.TypeName))\n            {\n                type = LookupType(typeResolver, ancestor.Namespace, ancestor.TypeName);\n            }\n\n            return new LogicalAncestorElementNode(type, ancestor.Level);\n        }\n\n        private static Type LookupType(\n            Func<string?, string, Type?>? typeResolver,\n            string? @namespace,\n            string? name)\n        {\n            if (name is null)\n                throw new InvalidOperationException($\"Unable to resolve unnamed type from namespace '{@namespace}'.\");\n            return typeResolver?.Invoke(@namespace, name) ??\n                throw new InvalidOperationException($\"Unable to resolve type '{@namespace}:{name}'.\");\n        }\n    }\n}\n","sourceCodeStart":125,"sourceCodeEnd":147,"githubUrl":"https://github.com/AvaloniaUI/Avalonia/blob/11c542726898ae954a1ef668c65ec79ec92ab17d/src/Avalonia.Base/Data/Core/Parsers/ExpressionNodeFactory.cs#L125-L147","documentation":"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).","triggerScenarios":"{Binding $ancestor[UnknownType]}, (UnknownNs:UnknownType), a type from an unreferenced assembly, or a type stripped by trimming so the resolver cannot find it.","commonSituations":"Missing or wrong xmlns mapping; unreferenced assembly; typo in the type name; AOT/trimming removing the type metadata the resolver depends on.","solutions":["Add the correct xmlns and assembly reference so the resolver can map the type.","Fix the type name spelling.","For trimming/AOT, ensure the referenced type is rooted/preserved."],"exampleFix":"<!-- before -->\n{Binding $ancestor[Foo]}  <!-- Foo not resolvable -->\n<!-- after -->\nxmlns:ctrl=\"clr-namespace:MyApp.Controls\"\n{Binding $ancestor[ctrl:Foo]}","handlingStrategy":"validation","validationCode":"// Resolve the type through the same resolver the binding will use, up front:\nType? resolved = typeResolver?.Invoke(@namespace, typeName);\nif (resolved is null) { /* fix xmlns/assembly before binding */ }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure correct xmlns mappings and assembly references for all types used in bindings.","Verify type names against the actual CLR types.","For trimming/AOT, preserve referenced type metadata."],"tags":["binding","reflection-binding","xaml","type-resolution","trimming"],"backgroundTag":null,"analyzedSha":"11c542726898ae954a1ef668c65ec79ec92ab17d","analyzedAt":"2026-08-13T11:57:40.261Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}