Description
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:
Constructor_GetGenericArguments.zip
Expected behavior
GetGenericArguments() should return an empy array.
Actual behavior
The call throws an exception, seemingly because GetGenericArguments() is not overridden in RuntimeConstructorInfo.
Regression?
No response
Known Workarounds
I check MethodBase.IsGenericMethod first, because this is false for constructors; I can then assume that GetGenericArguments() is empty.
Configuration
.NET version: 10.0.203
OS version: Windows 11 Pro 22H2
CPU architecture: x64
Other information
No response
Description
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:
I have created a tiny project that reproduces the problem - at least on my machine:
Constructor_GetGenericArguments.zip
Expected behavior
GetGenericArguments() should return an empy array.
Actual behavior
The call throws an exception, seemingly because GetGenericArguments() is not overridden in RuntimeConstructorInfo.
Regression?
No response
Known Workarounds
I check MethodBase.IsGenericMethod first, because this is false for constructors; I can then assume that GetGenericArguments() is empty.
Configuration
.NET version: 10.0.203
OS version: Windows 11 Pro 22H2
CPU architecture: x64
Other information
No response