Skip to content

[Mono] Support invoking string and array constructors on existing objects #134902

Description

@jkoritzinsky

Description

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

Mono 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 Mono:

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 Mono with TargetInvocationException wrapping NotSupportedException, matching CoreCLR.

Actual behavior

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

Regression?

Unknown.

Known Workarounds

None.

Configuration

Mono 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

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions