Skip to content

Enum.GetUnderlyingType crashes the runtime on generic arguments constrained as Enums #71884

@jkotas

Description

@jkotas

Repro:

Type param = typeof(MyG<>).GetGenericArguments()[0];
Console.WriteLine(Enum.GetUnderlyingType(param));

class MyG<T> where T: Enum
{
}

Actual result: Fatal error. Internal CLR error.
Expected result: ArgumentException

The problem is that the Type.IsEnum returns true for generic arguments constrained as enums. It makes the IsEnum argument checks pass, but the code that follows does not expect generic arguments.

There are likely other places that use IsEnum for argument checks and that will have similar problem.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions