Skip to content

[NativeAOT] Support invoking string and array constructors on existing objects #134900

Closed

Description

@jkoritzinsky

Description

The reflection tests ConstructorInfoTests.Invoke_StringConstructorWithExistingInstance and Invoke_ArrayConstructorWithExistingInstance are currently limited to CoreCLR because NativeAOT does not support invoking string and array pseudo-constructors against existing objects.

NativeAOT should match the expected reflection behavior for these constructor handles. The tests exercise the existing-object path and expect the runtime's documented NotSupportedException behavior to be surfaced through TargetInvocationException.

Reproduction Steps

Run these tests from src/libraries/System.Runtime/tests/System.Reflection.Tests/ConstructorInfoTests.cs on NativeAOT:

ConstructorInfo stringConstructor = typeof(string).GetConstructor(new[] { typeof(char[]) })!;
TargetInvocationException stringException = Assert.Throws<TargetInvocationException>(() =>
    stringConstructor.Invoke("existing", new object?[] { new[] { 'n', 'e', 'w' } }));
Assert.IsType<NotSupportedException>(stringException.InnerException);

ConstructorInfo arrayConstructor = typeof(object[]).GetConstructor(new[] { typeof(int) })!;
TargetInvocationException arrayException = Assert.Throws<TargetInvocationException>(() =>
    arrayConstructor.Invoke(new object[1], new object?[] { 3 }));
Assert.IsType<NotSupportedException>(arrayException.InnerException);

Expected behavior

Both tests pass on NativeAOT with TargetInvocationException wrapping NotSupportedException, matching CoreCLR.

Actual behavior

These constructor-on-existing-object cases are not currently supported on NativeAOT, so the tests are guarded to CoreCLR.

Regression?

Unknown.

Known Workarounds

None.

Configuration

NativeAOT runtime; System.Reflection.Tests.

Other information

Relevant tests: src/libraries/System.Runtime/tests/System.Reflection.Tests/ConstructorInfoTests.cs.

[!NOTE] This issue was filed with assistance from GitHub Copilot.

Activity

  1. added
    untriaged
    on Sep 29, 2026
  2. dotnet-policy-service commented on Sep 29, 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 Nov 4, 2026
  4. added a commit that references this issue on Nov 4, 2026
    aff3401
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions