{"record":{"id":"6ae8f3ccf12f7b02","repo":"unoplatform/uno","slug":"serviceprovider-does-not-implement-ixamlnameresolv","errorCode":null,"errorMessage":"serviceProvider does not implement IXamlNameResolver","messagePattern":"serviceProvider does not implement IXamlNameResolver","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Windows.Markup/Bind.cs","lineNumber":41,"sourceCode":"\t\t[ConstructorArgument (\"path\")]\n\t\tpublic string Path { get; set; }\n\n\t\tpublic override object ProvideValue (IServiceProvider serviceProvider)\n\t\t{\n\t\t\tif (serviceProvider == null)\n\t\t\t{\n\t\t\t\tthrow new ArgumentNullException (\"serviceProvider\");\n\t\t\t}\n\n\t\t\tif (Path == null)\n\t\t\t{\n\t\t\t\tthrow new InvalidOperationException (\"Name property is not set\");\n\t\t\t}\n\n\t\t\tvar r = serviceProvider.GetService (typeof (IXamlNameResolver)) as IXamlNameResolver;\n\t\t\tif (r == null)\n\t\t\t{\n\t\t\t\tthrow new InvalidOperationException (\"serviceProvider does not implement IXamlNameResolver\");\n\t\t\t}\n\n\t\t\tvar ret = r.Resolve (Path);\n\t\t\tif (ret == null)\n\t\t\t{\n\t\t\t\tret = r.GetFixupToken (new string [] { Path }, true);\n\t\t\t}\n\n\t\t\treturn ret;\n\t\t}\n\t}\n}\n","sourceCodeStart":23,"sourceCodeEnd":54,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Windows.Markup/Bind.cs#L23-L54","documentation":"InvalidOperationException thrown by Bind.ProvideValue (System.Xaml, ported from Mono) when the supplied IServiceProvider does not return an IXamlNameResolver from GetService. Bind resolves its Path against the XAML name table, so a provider lacking the name resolver cannot fulfill the request. This indicates the wrong service context (not a real XAML object-writer context).","triggerScenarios":"Passing a service provider that does not implement/return IXamlNameResolver — e.g. a stub provider in tests or a non-XAML hosting environment.","commonSituations":"Unit-test providers that only implement some services, a custom markup-extension host that does not expose the name resolver, or calling ProvideValue outside the XAML object-writer pipeline.","solutions":["Use the service provider from a real XAML object writer, which supplies IXamlNameResolver.","In tests, make GetService(typeof(IXamlNameResolver)) return a working IXamlNameResolver implementation.","Confirm the host pipeline wires the name resolver before invoking markup extensions."],"exampleFix":"// before\nvar sp = new StubProvider(); // GetService returns null for IXamlNameResolver\nbind.ProvideValue(sp);\n\n// after\nvar sp = new ServiceProviderWithResolver(nameResolver);\nbind.ProvideValue(sp);","handlingStrategy":"type-guard","validationCode":"static bool ProviderHasNameResolver(IServiceProvider sp) => sp.GetService(typeof(IXamlNameResolver)) is IXamlNameResolver;","typeGuard":"static bool IsXamlContext(IServiceProvider sp) => sp?.GetService(typeof(IXamlNameResolver)) is IXamlNameResolver;","tryCatchPattern":"try { return bind.ProvideValue(sp); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"IXamlNameResolver\")) { throw new InvalidOperationException(\"Bind must run inside a XAML object-writer context.\"); }","preventionTips":["Use the service provider from a real XAML object writer.","In tests, make GetService return a working IXamlNameResolver.","Confirm the host pipeline wires the name resolver before evaluating markup extensions."],"tags":["xaml","markup-extension","bind","invalidoperation","iservicelocator","system-xaml"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}