{"record":{"id":"0506957588817f84","repo":"unoplatform/uno","slug":"underlyingtype","errorCode":null,"errorMessage":"underlyingType","messagePattern":"underlyingType","errorType":"validation","errorClass":"ArgumentNullException","httpStatus":null,"severity":"error","filePath":"src/SourceGenerators/System.Xaml/System.Xaml/XamlType.cs","lineNumber":55,"sourceCode":"\t[UnconditionalSuppressMessage(\"Trimming\", \"IL2072\", Justification = \"Types manipulated here have been marked earlier\")]\n\t[UnconditionalSuppressMessage(\"Trimming\", \"IL2075\", Justification = \"Types manipulated here have been marked earlier\")]\n\t[UnconditionalSuppressMessage(\"Trimming\", \"IL2080\", Justification = \"Types manipulated here have been marked earlier\")]\n\tpublic class XamlType : IEquatable<XamlType>\n\t{\n\t\tpublic XamlType (Type underlyingType, XamlSchemaContext schemaContext)\n\t\t\t: this (underlyingType, schemaContext, null)\n\t\t{\n\t\t}\n\n//\t\tstatic readonly Type [] predefined_types = {\n//\t\t\t\ttypeof (XData), typeof (Uri), typeof (TimeSpan), typeof (PropertyDefinition), typeof (MemberDefinition), typeof (Reference)\n//\t\t\t};\n\n\t\tpublic XamlType (Type underlyingType, XamlSchemaContext schemaContext, XamlTypeInvoker invoker)\n\t\t\t: this (schemaContext, invoker)\n\t\t{\n\t\t\tif (underlyingType == null)\n\t\t\t\tthrow new ArgumentNullException (\"underlyingType\");\n\t\t\ttype = underlyingType;\n\t\t\tunderlying_type = type;\n\n\t\t\tXamlType xt;\n\t\t\tif (XamlLanguage.InitializingTypes) {\n\t\t\t\t// These are special. Only XamlLanguage members are with shorthand name.\n\t\t\t\tif (type == typeof (PropertyDefinition))\n\t\t\t\t\tName = \"Property\";\n\t\t\t\telse if (type == typeof (MemberDefinition))\n\t\t\t\t\tName = \"Member\";\n\t\t\t\telse\n\t\t\t\t\tName = GetXamlName (type);\n\t\t\t\tPreferredXamlNamespace = XamlLanguage.Xaml2006Namespace;\n\t\t\t} else if ((xt = XamlLanguage.AllTypes.FirstOrDefault (t => t.UnderlyingType == type)) != null) {\n\t\t\t\tName = xt.Name;\n\t\t\t\tPreferredXamlNamespace = XamlLanguage.Xaml2006Namespace;\n\t\t\t} else {\n\t\t\t\tName = GetXamlName (type);","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/unoplatform/uno/blob/04183404888ea21b4e5bfa3493e8d5f15e972c3a/src/SourceGenerators/System.Xaml/System.Xaml/XamlType.cs#L37-L73","documentation":"The XamlType(Type underlyingType, XamlSchemaContext, XamlTypeInvoker) constructor throws ArgumentNullException('underlyingType') when given a null Type. XamlType wraps a CLR type, so a null type leaves it with nothing to describe; the constructor also reads type.IsGenericType downstream, which would NRE otherwise.","triggerScenarios":"Constructing XamlType from a Type obtained via reflection that returned null (e.g. Type.GetType on a non-resolved name), or passing a nullable Type variable without checking.","commonSituations":"Reflection-based code that resolves types by string and silently returns null on failure; deserialization that builds XamlType from dynamically loaded types; partial/generics handling where GetType returns null for an open generic.","solutions":["Resolve the Type up front and throw a descriptive error if null before constructing XamlType.","Use Type.GetType with throwOnError=true (or Assembly.GetType and check) so a missing type fails loudly at the source.","If the type is genuinely unknown, use the XamlType(string,string,IList<XamlType>,XamlSchemaContext) overload that represents an unknown type instead of the Type-based one."],"exampleFix":"// before\nvar t = Type.GetType(typeName);\nvar xt = new XamlType(t, schemaContext, null);\n\n// after\nvar t = Type.GetType(typeName, throwOnError: true);\nvar xt = new XamlType(t, schemaContext, null);","handlingStrategy":"validation","validationCode":"if (underlyingType == null) throw new ArgumentNullException(nameof(underlyingType));\nvar xt = new XamlType(underlyingType, schemaContext, null);","typeGuard":"static XamlType? SafeXamlType(Type? t, XamlSchemaContext sctx)\n    => t is null ? null : new XamlType(t, sctx, null);","tryCatchPattern":null,"preventionTips":["Resolve types with Type.GetType(name, throwOnError: true) so missing types fail loudly before reaching XamlType.","Use the unknown-type XamlType overload when you intentionally represent an unresolved type."],"tags":["xaml","argument-null","xamltype","reflection"],"backgroundTag":null,"analyzedSha":"04183404888ea21b4e5bfa3493e8d5f15e972c3a","analyzedAt":"2026-08-13T21:08:11.651Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}