Skip to content

GetGenericArguments throws NotSupportedException on ConstructorInfo #128041

Closed
dotnet/dotnet-api-docs
#12616

Description

@taco-indenbosch

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

Activity

  1. added
    untriaged
    on May 11, 2026
  2. dotnet-policy-service commented on May 11, 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.

  3. removed
    untriaged
    on May 12, 2026
  4. steveisok commented on May 12, 2026

    @steveisok
    Member

    @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.

  5. jkotas commented on May 12, 2026

    @jkotas
    Member
  6. added a commit that references this issue on May 13, 2026
    214a9a4
  7. locked and limited conversation to collaborators on Jun 12, 2026
  8. added a commit that references this issue on Jul 15, 2026
    ec13ee4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions