You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
GetGenericArguments throws NotSupportedException on ConstructorInfo #128041
I would expect MethodBase.GetGenericArguments() to return an empty array when calling on any non-generic method including constructors. A NotSupportedException with the message "Derived classes must provide an implementation" is thrown instead when called on a ConstructorInfo object.
Reproduction Steps
This unit test fails:
namespace TestProject1
{
[TestClass]
public sealed class Test1
{
[TestMethod]
public void TestMethod1()
{
var ctor = typeof(SimpleClass).GetConstructor(new[] { typeof(int) });
Assert.IsEmpty(ctor.GetGenericArguments());
}
}
public class SimpleClass
{
public SimpleClass(int x)
{ }
}
}
I have created a tiny project that reproduces the problem - at least on my machine:
@jkotas I put up a PR for this, but it would be a breaking change if we took it. I imagine our original intent was to throw to make it super apparent and not be misleading with an empty array.
Activity
dotnet-policy-service commentedon May 11, 2026
Tagging subscribers to this area: @steveisok, @dotnet/area-system-reflection
See info in area-owners.md if you want to be subscribed.
steveisok commentedon May 12, 2026
@jkotas I put up a PR for this, but it would be a breaking change if we took it. I imagine our original intent was to throw to make it super apparent and not be misleading with an empty array.
jkotas commentedon May 12, 2026
Replacing an exception with reasonable behavior is allowed change: https://github.com/dotnet/runtime/blob/main/docs/coding-guidelines/breaking-change-rules.md#exceptions . I do not see a problem with fixing this.
Fix ConstructorInfo.GetGenericArguments to return empty array (#128059)
Fix ConstructorInfo.GetGenericArguments to return empty array (#128059)