{"record":{"id":"0b1f2fcb65dafd72","repo":"unoplatform/uno","slug":"serviceprovider-0b1f2f","errorCode":null,"errorMessage":"serviceProvider","messagePattern":"serviceProvider","errorType":"exception","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Windows.Markup/TypeExtension.cs","lineNumber":81,"sourceCode":"\t\tpublic Type Type { get; set; }\n\t\t[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]\n\t\tpublic string TypeName { get; set; }\n\n\t\tpublic override object ProvideValue (IServiceProvider serviceProvider)\n\t\t{\n\t\t\tif (Type != null)\n\t\t\t{\n\t\t\t\treturn Type;\n\t\t\t}\n\n\t\t\tif (TypeName == null)\n\t\t\t{\n\t\t\t\tthrow new InvalidOperationException (\"Either TypeName or Type must be filled before calling ProvideValue method\");\n\t\t\t}\n\n\t\t\tif (serviceProvider == null) // it can be null when Type is supplied.\n\t\t\t{\n\t\t\t\tthrow new ArgumentNullException (\"serviceProvider\");\n\t\t\t}\n\n\t\t\tvar p = serviceProvider.GetService (typeof (IXamlTypeResolver)) as IXamlTypeResolver;\n\t\t\tif (p == null)\n\t\t\t{\n\t\t\t\tthrow new InvalidOperationException (\"serviceProvider does not provide IXamlTypeResolver service.\");\n\t\t\t}\n\n\t\t\tvar ret = p.Resolve (TypeName);\n\t\t\tif (ret == null)\n\t\t\t{\n\t\t\t\tthrow new InvalidOperationException (String.Format (CultureInfo.InvariantCulture, \"Type '{0}' is not resolved as a valid type by the type resolver '{1}'.\", TypeName, p.GetType ()));\n\t\t\t}\n\n\t\t\treturn ret;\n\t\t}\n\t}\n}","sourceCodeStart":63,"sourceCodeEnd":99,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Windows.Markup/TypeExtension.cs#L63-L99","documentation":"Thrown by TypeExtension.ProvideValue when serviceProvider is null and TypeName (not Type) is being resolved. The comment in source notes serviceProvider may legitimately be null only when Type is supplied; otherwise a resolver is required to turn the string into a Type.","triggerScenarios":"Calling ProvideValue(null) when Type is null and TypeName is set; manually invoking the extension outside a XAML context.","commonSituations":"Unit tests or tooling that call ProvideValue without provisioning services; refactors that dropped the service provider argument.","solutions":["Always pass a non-null IServiceProvider that advertises IXamlTypeResolver when TypeName-based resolution is needed.","Prefer setting the Type property directly so the serviceProvider argument is not required.","Guard: if Type is null, ensure serviceProvider is non-null before calling ProvideValue."],"exampleFix":"// before\nvar ext = new TypeExtension { TypeName = \"local:MyControl\" };\nvar v = ext.ProvideValue(null); // throws\n\n// after\nvar ext = new TypeExtension { TypeName = \"local:MyControl\" };\nvar v = ext.ProvideValue(serviceProviderWithTypeResolver);","handlingStrategy":"validation","validationCode":"// When using TypeName resolution, provider must be non-null\nvar ext = new TypeExtension { TypeName = \"local:MyControl\" };\nif (ext.Type == null && sp == null)\n    throw new ArgumentNullException(nameof(sp));\nvar value = ext.ProvideValue(sp);","typeGuard":"static bool SafeToProvideValue(TypeExtension e, IServiceProvider sp)\n    => e.Type != null || sp != null;","tryCatchPattern":null,"preventionTips":["Prefer setting Type so the provider becomes optional.","When TypeName-only, always thread a non-null service provider through.","Document that ProvideValue(null) is only valid when Type is set."],"tags":["xaml","markup-extension","type-extension","argument-null","uno"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}