{"record":{"id":"bb7e77b74f1b48c6","repo":"dotnet/reactive","slug":"type-does-not-have-an-element-type","errorCode":null,"errorMessage":"{type} does not have an element type","messagePattern":"(.+?) does not have an element type","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"Ix.NET/Source/ApiCompare/Program.cs","lineNumber":563,"sourceCode":"                    return VisitGeneric(type);\n                }\n                else if (type.IsByRef)\n                {\n                    return VisitByRef(type);\n                }\n                else if (type.IsPointer)\n                {\n                    return VisitPointer(type);\n                }\n                else\n                {\n                    return VisitSimple(type);\n                }\n            }\n\n            protected virtual Type VisitArray(Type type)\n            {\n                return Visit(type.GetElementType() ?? throw new ArgumentException($\"{type} does not have an element type\")).MakeArrayType();\n            }\n\n            protected virtual Type VisitMultidimensionalArray(Type type)\n            {\n                return Visit(type.GetElementType() ?? throw new ArgumentException($\"{type} does not have an element type\")).MakeArrayType(type.GetArrayRank());\n            }\n\n            protected virtual Type VisitGenericTypeDefinition(Type type)\n            {\n                return type;\n            }\n\n            protected virtual Type VisitGeneric(Type type)\n            {\n                return Visit(type.GetGenericTypeDefinition()).MakeGenericType(Visit(type.GenericTypeArguments));\n            }\n\n            protected virtual Type VisitByRef(Type type)","sourceCodeStart":545,"sourceCodeEnd":581,"githubUrl":"https://github.com/dotnet/reactive/blob/94b5d5ab912789f5abe9a72138a25bbd716fe59c/Ix.NET/Source/ApiCompare/Program.cs#L545-L581","documentation":"ApiCompare's reflection TypeVisitor calls Type.GetElementType() for an array type and throws ArgumentException when it returns null. This happens when the type reported itself as an array (Visitor dispatched VisitArray) but has no element type - typically an open generic array parameter (e.g. the array shape of an unconstrained generic type parameter) or a malformed/by-ref array type from a different metadata context.","triggerScenarios":"Visit/VisitArray invoked with a Type where IsArray is true but GetElementType() is null, e.g. T[] where T is an open generic type parameter being compared across assemblies.","commonSituations":"API comparison runs over assemblies containing generic type parameters used as arrays; comparing netstandard vs framework builds where array element types resolve differently.","solutions":["Skip or special-case open generic type parameters (IsGenericParameter) before array traversal in the visitor","Close/normalize generic types before running the API comparison","Wrap VisitArray calls to handle ArgumentException for null element types"],"exampleFix":"// before\nreturn Visit(type.GetElementType() ?? throw new ArgumentException(...)).MakeArrayType();\n// after\nif (type.IsGenericParameter) return type;\nreturn Visit(type.GetElementType() ?? type).MakeArrayType();","handlingStrategy":"validation","validationCode":"if (type.IsArray && type.GetElementType() == null) skipType(type);","typeGuard":"bool HasElementType(Type t) => !t.IsArray || t.GetElementType() != null;","tryCatchPattern":"try { return VisitArray(type); } catch (ArgumentException ex) when (ex.Message.Contains(\"does not have an element type\")) { return type; }","preventionTips":["Skip open generic type parameters in type visitors","Close generics before reflection traversal","Load all referenced assemblies before comparison"],"tags":["reflection","arrays","apicompare","tooling"],"backgroundTag":"incompatible-source-type","analyzedSha":"94b5d5ab912789f5abe9a72138a25bbd716fe59c","analyzedAt":"2026-09-15T02:26:24.759Z","contentChangedAt":"2026-09-15T02:26:24.759Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}