{"record":{"id":"2060162442789e25","repo":"unoplatform/uno","slug":"either-typename-or-type-must-be-filled-before-call","errorCode":null,"errorMessage":"Either TypeName or Type must be filled before calling ProvideValue method","messagePattern":"Either TypeName or Type must be filled before calling ProvideValue method","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Windows.Markup/TypeExtension.cs","lineNumber":76,"sourceCode":"\t\t\tType = type;\n\t\t}\n\n\t\t[ConstructorArgument (\"type\")]\n\t\t[DefaultValue (null)]\n\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}","sourceCodeStart":58,"sourceCodeEnd":94,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Windows.Markup/TypeExtension.cs#L58-L94","documentation":"Thrown by TypeExtension.ProvideValue when both Type and TypeName are null. The extension can produce a value only if at least one is set (Type takes precedence and is returned directly; TypeName is resolved via IXamlTypeResolver).","triggerScenarios":"Calling ProvideValue on a default-constructed TypeExtension (new TypeExtension()) without assigning either Type or TypeName.","commonSituations":"Programmatic markup-extension construction that skips initialization; XAML parse paths where the x:Type directive has no operand; partial initialization in factories.","solutions":["Set Type (preferred when known) or TypeName before calling ProvideValue.","If using XAML, ensure x:Type arguments are populated, e.g. <x:Type TypeName=\"local:MyControl\"/>.","Add a precondition check before ProvideValue to surface a domain-specific error message."],"exampleFix":"// before\nvar ext = new TypeExtension();\nvar v = ext.ProvideValue(sp); // throws\n\n// after\nvar ext = new TypeExtension { TypeName = \"local:MyControl\" };\nvar v = ext.ProvideValue(sp);","handlingStrategy":"validation","validationCode":"var ext = new TypeExtension();\n// set either Type or TypeName before ProvideValue\nif (ext.Type == null && ext.TypeName == null)\n    throw new InvalidOperationException(\"TypeExtension requires Type or TypeName\");\nvar value = ext.ProvideValue(sp);","typeGuard":"static bool IsTypeExtensionReady(TypeExtension e) => e.Type != null || !string.IsNullOrEmpty(e.TypeName);","tryCatchPattern":null,"preventionTips":["Always initialize TypeExtension via one of its constructors or a builder that sets Type or TypeName.","In XAML, ensure x:Type directives always carry an operand.","Add an assertion in factory methods that create TypeExtension."],"tags":["xaml","markup-extension","type-extension","validation","uno"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}