From 6d4d532778b248f534484be276bd92f9de743cd5 Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Tue, 17 May 2022 12:21:16 -0700 Subject: [PATCH] Wrap exceptions from array constructors in TargetInvocationException (#69440) Fixes #69336 --- .../System/Reflection/Runtime/MethodInfos/CustomMethodInvoker.cs | 2 +- .../src/System/Reflection/Runtime/MethodInfos/InvokerOptions.cs | 1 - .../src/System/Reflection/Runtime/TypeInfos/RuntimeArrayTypeInfo.cs | 6 +++--- src/libraries/System.Reflection/tests/ConstructorInfoTests.cs | 1 - 4 files changed, 4 insertions(+), 6 deletions(-) diff --git a/src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/CustomMethodInvoker.cs b/src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/CustomMethodInvoker.cs index 95f5c55..9a00c69 100644 --- a/src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/CustomMethodInvoker.cs +++ b/src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/CustomMethodInvoker.cs @@ -42,7 +42,7 @@ namespace System.Reflection.Runtime.MethodInfos { result = _action(thisObject, convertedArguments, _thisType); } - catch (Exception e) when (wrapInTargetInvocationException && ((_options & InvokerOptions.DontWrapException) == 0)) + catch (Exception e) when (wrapInTargetInvocationException) { throw new TargetInvocationException(e); } diff --git a/src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/InvokerOptions.cs b/src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/InvokerOptions.cs index 4f222d7..4036e4f 100644 --- a/src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/InvokerOptions.cs +++ b/src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/InvokerOptions.cs @@ -8,6 +8,5 @@ namespace System.Reflection.Runtime.MethodInfos { None = 0x00000000, AllowNullThis = 0x00000001, // Don't raise an exception if the "thisObject" parameter to Invoker is null. - DontWrapException = 0x00000002, // Don't wrap target exceptions in TargetInvocationException. } } diff --git a/src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeArrayTypeInfo.cs b/src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeArrayTypeInfo.cs index b2bf8de..f46dd9a 100644 --- a/src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeArrayTypeInfo.cs +++ b/src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeArrayTypeInfo.cs @@ -71,7 +71,7 @@ namespace System.Reflection.Runtime.TypeInfos SyntheticMethodId.ArrayCtor, arrayType, ctorParameters, - InvokerOptions.AllowNullThis | InvokerOptions.DontWrapException, + InvokerOptions.AllowNullThis, delegate (object _this, object[] args, Type thisType) { int[] lengths = new int[rank]; @@ -109,7 +109,7 @@ namespace System.Reflection.Runtime.TypeInfos SyntheticMethodId.ArrayCtorJagged + parameterCount, arrayType, ctorParameters, - InvokerOptions.AllowNullThis | InvokerOptions.DontWrapException, + InvokerOptions.AllowNullThis, delegate (object _this, object[] args, Type thisType) { int[] lengths = new int[args.Length]; @@ -145,7 +145,7 @@ namespace System.Reflection.Runtime.TypeInfos SyntheticMethodId.ArrayMultiDimCtor, arrayType, ctorParameters, - InvokerOptions.AllowNullThis | InvokerOptions.DontWrapException, + InvokerOptions.AllowNullThis, delegate (object _this, object[] args, Type thisType) { int[] lengths = new int[rank]; diff --git a/src/libraries/System.Reflection/tests/ConstructorInfoTests.cs b/src/libraries/System.Reflection/tests/ConstructorInfoTests.cs index c499063..e6d59b7 100644 --- a/src/libraries/System.Reflection/tests/ConstructorInfoTests.cs +++ b/src/libraries/System.Reflection/tests/ConstructorInfoTests.cs @@ -115,7 +115,6 @@ namespace System.Reflection.Tests [Fact] [ActiveIssue("https://github.com/dotnet/runtime/issues/67457", TestRuntimes.Mono)] - [ActiveIssue("https://github.com/dotnet/runtime/issues/69336", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] public void Invoke_OneDimensionalArray_NegativeLengths_ThrowsOverflowException() { ConstructorInfo[] constructors = GetConstructors(typeof(object[])); -- 2.7.4