Wrap exceptions from array constructors in TargetInvocationException (#69440)
authorJan Kotas <jkotas@microsoft.com>
Tue, 17 May 2022 19:21:16 +0000 (12:21 -0700)
committerGitHub <noreply@github.com>
Tue, 17 May 2022 19:21:16 +0000 (12:21 -0700)
Fixes #69336

src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/CustomMethodInvoker.cs
src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/MethodInfos/InvokerOptions.cs
src/coreclr/nativeaot/System.Private.Reflection.Core/src/System/Reflection/Runtime/TypeInfos/RuntimeArrayTypeInfo.cs
src/libraries/System.Reflection/tests/ConstructorInfoTests.cs

index 95f5c55..9a00c69 100644 (file)
@@ -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);
             }
index 4f222d7..4036e4f 100644 (file)
@@ -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.
     }
 }
index b2bf8de..f46dd9a 100644 (file)
@@ -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];
index c499063..e6d59b7 100644 (file)
@@ -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[]));