Skip to content

Generic type nested enum type reflection regression on .NET 9.0+ #129423

Description

@hrumhurum

Description

When the method parameter type is a enum type defined in a generic class, the parameter default value can no longer be observed via Reflection API.

Reproduction Steps

The code demonstrating the problem:

using System;

public class Program
{
    public static void Main()
    {
        Action<MyContainer<int>.MyEnum> action = MyMethod;
        var type = action.Method.GetGenericMethodDefinition().GetParameters()[0].DefaultValue.GetType();

        Console.WriteLine(type);
    }

    static void MyMethod<T>(MyContainer<T>.MyEnum param = 0)
    {
    }
}

class MyContainer<T>
{
    public enum MyEnum
    {
        First,
        Second
    }
}

Expected behavior

MyContainer`1+MyEnum[T]

Actual behavior

Unhandled exception. System.ArgumentException: Specified type is not supported
   at System.RuntimeType.BoxCache..ctor(RuntimeType rt)
   at System.RuntimeType.BoxCache.Create(RuntimeType type)
   at System.RuntimeType.IGenericCacheEntry`1.CreateAndCache(RuntimeType type)
   at System.Runtime.CompilerServices.RuntimeHelpers.Box(Byte& target, RuntimeTypeHandle type)
   at System.Enum.InternalBoxEnum(RuntimeTypeHandle type, Int64 value)
   at System.Reflection.MdConstant.GetValue(MetadataImport scope, Int32 token, RuntimeTypeHandle fieldTypeHandle, Boolean raw)
   at System.Reflection.RuntimeParameterInfo.TryGetDefaultValueInternal(Boolean raw, Object& defaultValue)
   at System.Reflection.RuntimeParameterInfo.GetDefaultValue(Boolean raw)
   at Program.Main()

Regression?

This is a regression.

The last version of .NET when the code was working: 8.0
The first version of .NET when the regression appeared: 9.0

Known Workarounds

No response

Configuration

> dotnet --list-sdks
8.0.422 [C:\Program Files\dotnet\sdk]
9.0.315 [C:\Program Files\dotnet\sdk]
10.0.301 [C:\Program Files\dotnet\sdk]

Other information

No response

Activity

  1. dotnet-policy-service commented on Jun 15, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @steveisok, @dotnet/area-system-reflection
    See info in area-owners.md if you want to be subscribed.

  2. added a commit that references this issue on Jul 1, 2026
    771b436
  3. added a commit that references this issue on Jul 15, 2026
    6e764ea
  4. locked and limited conversation to collaborators on Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions