Skip to content

Commit 6d4d532

Browse files
authored
Wrap exceptions from array constructors in TargetInvocationException (#69440)
Fixes #69336
1 parent cd0dff1 commit 6d4d532

File tree

4 files changed

+4
-6
lines changed

4 files changed

+4
-6
lines changed

src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/CustomMethodInvoker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ protected sealed override object Invoke(object thisObject, object[] arguments, B
4242
{
4343
result = _action(thisObject, convertedArguments, _thisType);
4444
}
45-
catch (Exception e) when (wrapInTargetInvocationException && ((_options & InvokerOptions.DontWrapException) == 0))
45+
catch (Exception e) when (wrapInTargetInvocationException)
4646
{
4747
throw new TargetInvocationException(e);
4848
}

src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/InvokerOptions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,5 @@ internal enum InvokerOptions
88
{
99
None = 0x00000000,
1010
AllowNullThis = 0x00000001, // Don't raise an exception if the "thisObject" parameter to Invoker is null.
11-
DontWrapException = 0x00000002, // Don't wrap target exceptions in TargetInvocationException.
1211
}
1312
}

src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeArrayTypeInfo.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ internal sealed override IEnumerable<RuntimeConstructorInfo> SyntheticConstructo
7171
SyntheticMethodId.ArrayCtor,
7272
arrayType,
7373
ctorParameters,
74-
InvokerOptions.AllowNullThis | InvokerOptions.DontWrapException,
74+
InvokerOptions.AllowNullThis,
7575
delegate (object _this, object[] args, Type thisType)
7676
{
7777
int[] lengths = new int[rank];
@@ -109,7 +109,7 @@ internal sealed override IEnumerable<RuntimeConstructorInfo> SyntheticConstructo
109109
SyntheticMethodId.ArrayCtorJagged + parameterCount,
110110
arrayType,
111111
ctorParameters,
112-
InvokerOptions.AllowNullThis | InvokerOptions.DontWrapException,
112+
InvokerOptions.AllowNullThis,
113113
delegate (object _this, object[] args, Type thisType)
114114
{
115115
int[] lengths = new int[args.Length];
@@ -145,7 +145,7 @@ internal sealed override IEnumerable<RuntimeConstructorInfo> SyntheticConstructo
145145
SyntheticMethodId.ArrayMultiDimCtor,
146146
arrayType,
147147
ctorParameters,
148-
InvokerOptions.AllowNullThis | InvokerOptions.DontWrapException,
148+
InvokerOptions.AllowNullThis,
149149
delegate (object _this, object[] args, Type thisType)
150150
{
151151
int[] lengths = new int[rank];

src/libraries/System.Reflection/tests/ConstructorInfoTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@ public void Invoke_OneDimensionalArray()
115115

116116
[Fact]
117117
[ActiveIssue("https://github.com/dotnet/runtime/issues/67457", TestRuntimes.Mono)]
118-
[ActiveIssue("https://github.com/dotnet/runtime/issues/69336", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))]
119118
public void Invoke_OneDimensionalArray_NegativeLengths_ThrowsOverflowException()
120119
{
121120
ConstructorInfo[] constructors = GetConstructors(typeof(object[]));

0 commit comments

Comments
 (0)