{"record":{"id":"3662002eaa7ffa1f","repo":"unoplatform/uno","slug":"value-0-of-type-1-is-not-of-or-convertible","errorCode":null,"errorMessage":"Value '{0}' (of type {1}) is not of or convertible to type {0} (member {3})","messagePattern":"Value '(.+?)' \\(of type (.+?)\\) is not of or convertible to type (.+?) \\(member (.+?)\\)","errorType":"exception","errorClass":"XamlObjectWriterException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs","lineNumber":546,"sourceCode":"\n\t\t\t// FIXME: this could be generalized by some means, but I cannot find any.\n\t\t\tif (xt.UnderlyingType == typeof (Type))\n\t\t\t\tvalue = new TypeExtension ((string) value).ProvideValue (service_provider);\n\t\t\tif (xt == XamlLanguage.Type && value is string)\n\t\t\t\tvalue = new TypeExtension ((string) value);\n\t\t\t\n\t\t\tif (IsAllowedType (xt, value))\n\t\t\t\treturn value;\n\n\t\t\tvar xtc = (xm != null ? xm.TypeConverter : null) ?? xt.TypeConverter;\n\t\t\tif (xtc != null && value != null) {\n\t\t\t\tvar tc = xtc.ConverterInstance;\n\t\t\t\tif (tc != null && tc.CanConvertFrom (value.GetType ()))\n\t\t\t\t\tvalue = tc.ConvertFrom (value);\n\t\t\t\treturn value;\n\t\t\t}\n\n\t\t\tthrow new XamlObjectWriterException (String.Format (CultureInfo.InvariantCulture, \"Value '{0}' (of type {1}) is not of or convertible to type {0} (member {3})\", value, value != null ? (object) value.GetType () : \"(null)\", xt, xm));\n\t\t}\n\n\t\tXamlType ResolveTypeFromName (string name)\n\t\t{\n\t\t\tvar nsr = (IXamlNamespaceResolver) service_provider.GetService (typeof (IXamlNamespaceResolver));\n\t\t\treturn sctx.GetXamlType (XamlTypeName.Parse (name, nsr));\n\t\t}\n\n\t\tbool IsAllowedType (XamlType xt, object value)\n\t\t{\n\t\t\treturn  xt == null ||\n\t\t\t\txt.UnderlyingType == null ||\n\t\t\t\txt.UnderlyingType.IsInstanceOfType (value) ||\n\t\t\t\tvalue == null && xt == XamlLanguage.Null ||\n\t\t\t\txt.IsMarkupExtension && IsAllowedType (xt.MarkupExtensionReturnType, value);\n\t\t}\n\t\t\n\t\tvoid InitializeObjectIfRequired (bool waitForParameters)","sourceCodeStart":528,"sourceCodeEnd":564,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Xaml/XamlObjectWriter.cs#L528-L564","documentation":"Thrown when a value is not assignable to the target XamlType and no TypeConverter could convert it — the final fallback after IsAllowedType and converter attempts both fail. Note: the format string has a placeholder bug ('type {0}' reuses index 0 instead of index 2 for the target type), so the rendered message may print the value where the target type should appear.","triggerScenarios":"Assigning a value whose type is incompatible with the member's type with no conversion path — e.g. a SolidColorBrush into an int property, or a string into a struct with no TypeConverter.","commonSituations":"Wrong object type placed in a XAML collection/property; TypeConverter attribute missing on a value type; XamlType with null UnderlyingType receiving concrete objects.","solutions":["Assign a value of the member's expected type (or a derived type).","Add a [TypeConverter] on the target type so string/object conversion succeeds.","Verify the member's XamlType and its TypeConverter are correctly resolved by the schema context."],"exampleFix":"<!-- before -->\n<Rectangle Fill=\"Red\" Tag=\"notInt\" />\n<!-- after: ensure value matches member type -->","handlingStrategy":"validation","validationCode":"// Confirm the value is assignable to the member type or a converter exists.\nif (!IsAllowedType(memberType, value)) {\n    var tc = memberType.TypeConverter?.ConverterInstance;\n    if (tc == null || !tc.CanConvertFrom(value.GetType()))\n        throw new InvalidOperationException($\"Value type {value.GetType()} not assignable to {memberType}.\");\n}","typeGuard":null,"tryCatchPattern":"try { /* load/write XAML */ }\ncatch (XamlObjectWriterException ex) when (ex.Message.Contains(\"not of or convertible\")) {\n    // assign a compatible value or add a TypeConverter to the target type.\n}","preventionTips":["Ensure values placed in properties match the declared member type.","Annotate custom value types with [TypeConverter] for string conversion.","Be aware the message has a format-string bug; verify types in code rather than trusting the rendered text."],"tags":["xaml","type-mismatch","type-conversion","object-writer","format-string-bug"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}