{"record":{"id":"a6d04ea5024a79c1","repo":"unoplatform/uno","slug":"type-property-must-be-set-before-calling-provideva","errorCode":null,"errorMessage":"Type property must be set before calling ProvideValue method","messagePattern":"Type property must be set before calling ProvideValue method","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Windows.Markup/ArrayExtension.cs","lineNumber":91,"sourceCode":"\t\t}\n\n\t\tpublic void AddChild (Object value)\n\t\t{\n\t\t\t// null is allowed.\n\t\t\tItems.Add (value);\n\t\t}\n\t\t\n\t\tpublic void AddText (string text)\n\t\t{\n\t\t\t// null is allowed.\n\t\t\tItems.Add (text);\n\t\t}\n\t\t\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\tthrow new InvalidOperationException (\"Type property must be set before calling ProvideValue method\");\n\t\t\t}\n\n\t\t\tbool invalid = false;\n\t\t\tforeach (var item in Items) {\n\t\t\t\tif (item == null) {\n\t\t\t\t\tif (Type.IsValueType)\n\t\t\t\t\t{\n\t\t\t\t\t\tinvalid = true;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\telse if (!Type.IsAssignableFrom (item.GetType ()))\n\t\t\t\t{\n\t\t\t\t\tinvalid = true;\n\t\t\t\t}\n\n\t\t\t\tif (invalid)\n\t\t\t\t{\n\t\t\t\t\tthrow new InvalidOperationException (String.Format (CultureInfo.InvariantCulture, \"Item in the array must be an instance of '{0}'\", Type));","sourceCodeStart":73,"sourceCodeEnd":109,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Windows.Markup/ArrayExtension.cs#L73-L109","documentation":"InvalidOperationException thrown by ArrayExtension.ProvideValue (System.Xaml, ported from Mono) when ProvideValue is called before the Type property has been set. x:ArrayExtension needs an element type to construct the array, so calling the markup extension's value provider without a type is a usage error. Typically Type is set via the x:Type attribute or the arrayType constructor argument in markup.","triggerScenarios":"Programmatically constructing ArrayExtension() (parameterless) and calling ProvideValue without setting Type; or XAML that omits the x:Type element type.","commonSituations":"Omitting the Type attribute on x:ArrayExtension in XAML, manually invoking ProvideValue in tests/code without configuring Type, or a code path that clears Type before evaluation.","solutions":["Set Type (via constructor or the Type property) before calling ProvideValue.","In XAML, always specify the element type, e.g. <x:Array x:Key=\"...\" Type=\"x:String\">.","Add a guard in code: if (ext.Type == null) ext.Type = typeof(...); before ProvideValue."],"exampleFix":"// before\nvar ext = new ArrayExtension();\next.Items.Add(\"a\");\nvar arr = ext.ProvideValue(sp); // Type is null\n\n// after\nvar ext = new ArrayExtension(typeof(string));\next.Items.Add(\"a\");\nvar arr = ext.ProvideValue(sp);","handlingStrategy":"validation","validationCode":"static object SafeProvide(ArrayExtension ext, IServiceProvider sp) { if (ext.Type is null) throw new InvalidOperationException(\"Set ArrayExtension.Type first.\"); return ext.ProvideValue(sp); }","typeGuard":"static bool IsReady(ArrayExtension ext) => ext.Type is not null;","tryCatchPattern":"try { return ext.ProvideValue(sp); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"Type property must be set\")) { ext.Type = typeof(object); return ext.ProvideValue(sp); }","preventionTips":["Always specify Type via constructor or property before ProvideValue.","In XAML, always declare the x:Array Type attribute.","Add a readiness check in code that builds ArrayExtension dynamically."],"tags":["xaml","markup-extension","x-array","invalidoperation","system-xaml"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}