{"record":{"id":"41c1e6886555fc31","repo":"unoplatform/uno","slug":"serviceprovider-does-not-implement-ixamlnameresolv-41c1e6","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/Reference.cs","lineNumber":63,"sourceCode":"\t\t[ConstructorArgument (\"name\")]\n\t\tpublic string Name { 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 (Name == 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 (Name);\n\t\t\tif (ret == null)\n\t\t\t{\n\t\t\t\tret = r.GetFixupToken (new string [] {Name}, true);\n\t\t\t}\n\n\t\t\treturn ret;\n\t\t}\n\t}\n}\n","sourceCodeStart":45,"sourceCodeEnd":76,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Windows.Markup/Reference.cs#L45-L76","documentation":"Thrown by the Reference markup extension (x:Reference) when ProvideValue cannot obtain an IXamlNameResolver service from the supplied IServiceProvider. The XAML object writer is expected to supply this service so that forward/name references can be resolved at load time. Its absence means the host is not a conforming XAML reader/writer stack.","triggerScenarios":"Calling Reference.ProvideValue(serviceProvider) where serviceProvider.GetService(typeof(IXamlNameResolver)) returns null. Happens when invoking the markup extension outside a real XAML load context, or with a stub/null service provider that does not advertise name-resolution services.","commonSituations":"Unit tests that call ProvideValue directly with a mock IServiceProvider; custom XAML writers that forget to register IXamlNameResolver; invoking markup extensions from non-XAML code paths (e.g. manual template instantiation).","solutions":["Do not call ProvideValue manually; let the XamlObjectWriter / XamlXmlReader pipeline invoke it, which supplies IXamlNameResolver.","If testing, supply a fake IServiceProvider whose GetService returns a IXamlNameResolver implementation for typeof(IXamlNameResolver).","Ensure the XAML schema context has been initialized with a name-scope so the resolver is non-null during load.","Verify x:Reference targets a name that exists within the same namescope."],"exampleFix":"// before\nvar ext = new Reference { Name = \"myBtn\" };\nvar value = ext.ProvideValue(new ServiceLocator()); // throws\n\n// after\nvar value = ext.ProvideValue(XamlObjectWriterContext.WithNameResolver(resolver));","handlingStrategy":"validation","validationCode":"// Validate the service provider before invoking the extension\npublic static bool CanResolveReference(IServiceProvider sp)\n{\n    return sp?.GetService(typeof(IXamlNameResolver)) is IXamlNameResolver;\n}\n\n// Usage\nif (!CanResolveReference(sp)) throw new InvalidOperationException(\"Name resolver missing\");\nvar value = new Reference { Name = \"btn\" }.ProvideValue(sp);","typeGuard":"static bool HasNameResolver(IServiceProvider sp)\n    => sp?.GetService(typeof(IXamlNameResolver)) is IXamlNameResolver;","tryCatchPattern":null,"preventionTips":["Always invoke markup extensions through the XamlObjectWriter pipeline rather than calling ProvideValue directly.","When unit-testing extensions, supply a fake IServiceProvider that advertises IXamlNameResolver.","Treat a null IXamlNameResolver as a host-configuration defect, not a runtime data error."],"tags":["xaml","markup-extension","name-resolution","service-provider","uno"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}