{"record":{"id":"a258ae3418f6d5d3","repo":"unoplatform/uno","slug":"serviceprovider-a258ae","errorCode":null,"errorMessage":"serviceProvider","messagePattern":"serviceProvider","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Windows.Markup/Reference.cs","lineNumber":52,"sourceCode":"\tpublic class Reference : MarkupExtension\n\t{\n\t\tpublic Reference ()\n\t\t{\n\t\t}\n\n\t\tpublic Reference (string name)\n\t\t{\n\t\t\tName = name;\n\t\t}\n\n\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}","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Windows.Markup/Reference.cs#L34-L70","documentation":"ArgumentNullException thrown by the Reference markup extension's ProvideValue (System.Xaml, ported from Mono) when the IServiceProvider argument is null. Reference (x:Reference) resolves a named element via IXamlNameResolver obtained from the provider, so a null provider makes resolution impossible. Parameter name 'serviceProvider' identifies the null argument.","triggerScenarios":"Calling Reference.ProvideValue(null) directly, e.g. in a unit test or code path that bypasses the XAML runtime supplying the provider.","commonSituations":"Unit tests invoking ProvideValue without a provider, custom hosting that drops the service context, or misuse of the extension outside markup evaluation.","solutions":["Always pass the IServiceProvider from the XAML runtime; never invoke ProvideValue without one.","In tests, supply a provider whose GetService returns an IXamlNameResolver.","Null-check the provider at the call site before invoking."],"exampleFix":"// before\nvar target = reference.ProvideValue(null);\n\n// after\nvar target = reference.ProvideValue(xamlServiceProvider);","handlingStrategy":"validation","validationCode":"static object SafeProvide(Reference r, IServiceProvider sp) { if (sp is null) throw new ArgumentNullException(nameof(sp)); return r.ProvideValue(sp); }","typeGuard":"static bool HasXamlServices(IServiceProvider sp) => sp?.GetService(typeof(IXamlNameResolver)) is not null;","tryCatchPattern":"try { return r.ProvideValue(sp); } catch (ArgumentNullException ex) when (ex.ParamName == \"serviceProvider\") { throw new InvalidOperationException(\"x:Reference must be evaluated within a XAML service context.\"); }","preventionTips":["Never invoke ProvideValue without the XAML runtime's provider.","In tests, supply a provider returning IXamlNameResolver.","Let the XAML object writer evaluate x:Reference."],"tags":["xaml","markup-extension","x-reference","argumentnull","system-xaml"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}