{"record":{"id":"bd037a78fa83d887","repo":"unoplatform/uno","slug":"serviceprovider","errorCode":null,"errorMessage":"serviceProvider","messagePattern":"serviceProvider","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Windows.Markup/Bind.cs","lineNumber":30,"sourceCode":"\tpublic class Bind : MarkupExtension\n\t{\n\t\tpublic Bind()\n\t\t{\n\t\t}\n\n\t\tpublic Bind(string path)\n\t\t{\n\t\t\tPath = path;\n\t\t}\n\n\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}","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Windows.Markup/Bind.cs#L12-L48","documentation":"ArgumentNullException thrown by the Bind markup extension's ProvideValue (System.Xaml, ported from Mono) when the IServiceProvider argument is null. Bind resolves a named target via IXamlNameResolver obtained from the service provider, so a null provider makes resolution impossible. Parameter name 'serviceProvider' identifies the null argument.","triggerScenarios":"Calling Bind.ProvideValue(null) directly, e.g. in a unit test or code path that bypasses the XAML runtime which normally supplies the provider.","commonSituations":"Unit tests invoking ProvideValue without building a service provider, or custom hosting code that forgets to pass the XAML service context.","solutions":["Always pass the IServiceProvider supplied by the XAML runtime; never call ProvideValue manually without one.","In tests, build a minimal service provider implementing GetService to return an IXamlNameResolver.","Null-check the provider at the call site and fail with a clearer message before invoking."],"exampleFix":"// before\nvar value = bind.ProvideValue(null);\n\n// after\nvar value = bind.ProvideValue(xamlServiceProvider);","handlingStrategy":"validation","validationCode":"static object SafeProvide(Bind b, IServiceProvider sp) { if (sp is null) throw new ArgumentNullException(nameof(sp)); return b.ProvideValue(sp); }","typeGuard":"static bool HasXamlServices(IServiceProvider sp) => sp?.GetService(typeof(IXamlNameResolver)) is not null;","tryCatchPattern":"try { return bind.ProvideValue(sp); } catch (ArgumentNullException ex) when (ex.ParamName == \"serviceProvider\") { throw new InvalidOperationException(\"Bind must be evaluated within a XAML service context.\"); }","preventionTips":["Never call ProvideValue without the XAML runtime's service provider.","In tests, build a provider that returns IXamlNameResolver from GetService.","Let the XAML object writer drive markup extension evaluation."],"tags":["xaml","markup-extension","bind","argumentnull","system-xaml"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}