dotnet/reactive · error · ArgumentException
{type} does not have an element type
Error message
{type} does not have an element type What it means
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.
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
Example fix
// before return Visit(type.GetElementType() ?? throw new ArgumentException(...)).MakeArrayType(); // after if (type.IsGenericParameter) return type; return Visit(type.GetElementType() ?? type).MakeArrayType();
Defensive patterns
Strategy: validation
Validate before calling
if (type.IsArray && type.GetElementType() == null) skipType(type);
Type guard
bool HasElementType(Type t) => !t.IsArray || t.GetElementType() != null;
Try / catch
try { return VisitArray(type); } catch (ArgumentException ex) when (ex.Message.Contains("does not have an element type")) { return type; } Prevention
- Skip open generic type parameters in type visitors
- Close generics before reflection traversal
- Load all referenced assemblies before comparison
When it happens
Trigger: 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.
Common situations: API comparison runs over assemblies containing generic type parameters used as arrays; comparing netstandard vs framework builds where array element types resolve differently.
Understand the failure class
Background: "is not a compatible type" / "cannot merge" errors: when a value's type doesn't match what the library requires — this error's family across 65 libraries.
Related errors
- Invalid return type for + m.Name
- nameof(target)
- nameof(eventName)
- nameof(type)
- Could not find static event '{0}' on type '{1}'.
AI-assisted analysis of dotnet/reactive@94b5d5ab91 (2026-09-15).
Data as JSON: /api/errors/bb7e77b74f1b48c6.
Report an issue: GitHub.
Appendix: source
Thrown at Ix.NET/Source/ApiCompare/Program.cs:563
return VisitGeneric(type);
}
else if (type.IsByRef)
{
return VisitByRef(type);
}
else if (type.IsPointer)
{
return VisitPointer(type);
}
else
{
return VisitSimple(type);
}
}
protected virtual Type VisitArray(Type type)
{
return Visit(type.GetElementType() ?? throw new ArgumentException($"{type} does not have an element type")).MakeArrayType();
}
protected virtual Type VisitMultidimensionalArray(Type type)
{
return Visit(type.GetElementType() ?? throw new ArgumentException($"{type} does not have an element type")).MakeArrayType(type.GetArrayRank());
}
protected virtual Type VisitGenericTypeDefinition(Type type)
{
return type;
}
protected virtual Type VisitGeneric(Type type)
{
return Visit(type.GetGenericTypeDefinition()).MakeGenericType(Visit(type.GenericTypeArguments));
}
protected virtual Type VisitByRef(Type type)View on GitHub (pinned to 94b5d5ab91)