{"record":{"id":"67a08f693688fb90","repo":"unoplatform/uno","slug":"current-operation-is-valid-only-when-the-underlyin","errorCode":null,"errorMessage":"Current operation is valid only when the underlying type on a XamlType is known, but it is unknown for '{0}'","messagePattern":"Current operation is valid only when the underlying type on a XamlType is known, but it is unknown for '(.+?)'","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Xaml.Schema/XamlTypeInvoker.cs","lineNumber":60,"sourceCode":"\t\t}\n\n\t\tprotected XamlTypeInvoker ()\n\t\t{\n\t\t}\n\t\t\n\t\tpublic XamlTypeInvoker (XamlType type)\n\t\t{\n\t\t\tif (type == null)\n\t\t\t\tthrow new ArgumentNullException (\"type\");\n\t\t\tthis.type = type;\n\t\t}\n\t\t\n\t\tXamlType type;\n\n\t\tvoid ThrowIfUnknown ()\n\t\t{\n\t\t\tif (type == null || type.UnderlyingType == null)\n\t\t\t\tthrow new NotSupportedException (String.Format (CultureInfo.InvariantCulture, \"Current operation is valid only when the underlying type on a XamlType is known, but it is unknown for '{0}'\", type));\n\t\t}\n\n\t\tpublic EventHandler<XamlSetMarkupExtensionEventArgs> SetMarkupExtensionHandler {\n\t\t\tget { return type == null ? null : type.SetMarkupExtensionHandler; }\n\t\t}\n\n\t\tpublic EventHandler<XamlSetTypeConverterEventArgs> SetTypeConverterHandler {\n\t\t\tget { return type == null ? null : type.SetTypeConverterHandler; }\n\t\t}\n\n\t\tpublic virtual void AddToCollection (object instance, object item)\n\t\t{\n\t\t\tif (instance == null)\n\t\t\t\tthrow new ArgumentNullException (\"instance\");\n\t\t\tif (item == null)\n\t\t\t\tthrow new ArgumentNullException (\"item\");\n\n\t\t\tvar ct = instance.GetType ();","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Xaml.Schema/XamlTypeInvoker.cs#L42-L78","documentation":"Thrown by XamlTypeInvoker.ThrowIfUnknown when the invoker's type is null (UnknownInvoker) or when type.UnderlyingType is null (the XamlType has no backing CLR type). Several operations (CreateInstance, and the contract for collection/dictionary manipulation) require a real CLR type to reflect over. With an unknown or unbacked XamlType, reflection is impossible.","triggerScenarios":"Calling invoker operations on XamlTypeInvoker.UnknownInvoker, or on an invoker for a XamlType whose UnderlyingType is null (e.g. a XamlType built purely from name without CLR type info, common for generic/unknown types in the schema). CreateInstance calls ThrowIfUnknown directly.","commonSituations":"XAML referencing types not present in loaded assemblies; using a XamlSchemaContext that returns schema-only XamlTypes; dynamic/XAML-first scenarios where the CLR type is intentionally unknown; trimming that removed the underlying type.","solutions":["Ensure the XamlType has a non-null UnderlyingType before invoking reflection operations — check `xamlType.UnderlyingType != null`.","Do not call CreateInstance or collection operations on UnknownInvoker.","Fix type loading: add the assembly reference, fix xmlns namespace to a CLR namespace, or disable trimming for the relevant types.","Differentiate schema-only types from reflectable types in your writer and skip reflection ops on the former."],"exampleFix":"// before\nobject obj = xamlType.Invoker.CreateInstance(args);\n\n// after\nif (xamlType.UnderlyingType == null) {\n    throw new InvalidOperationException(\"Cannot instantiate XamlType with no underlying CLR type: \" + xamlType);\n}\nobject obj = xamlType.Invoker.CreateInstance(args);","handlingStrategy":"validation","validationCode":"// before reflection operations\nif (xamlType.UnderlyingType == null) {\n    throw new InvalidOperationException(\"XamlType has no underlying CLR type; cannot use reflection invoker.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never call CreateInstance or collection ops on UnknownInvoker.","Ensure referenced types are loaded; fix xmlns-to-CLR-namespace mappings.","Under trimming, preserve types needed for reflection."],"tags":["xaml","schema","invoker","type-resolution","reflection"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}