Fix empty ParamName in ArgumentException (#36208)
authorYoussef Victor <31348972+Youssef1313@users.noreply.github.com>
Mon, 11 May 2020 23:34:17 +0000 (01:34 +0200)
committerGitHub <noreply@github.com>
Mon, 11 May 2020 23:34:17 +0000 (16:34 -0700)
* Update reflectioninvocation.cpp

* Update TypeInfoTests.cs

* Update EnumConverterTest.cs

src/coreclr/src/vm/reflectioninvocation.cpp
src/libraries/System.ComponentModel.TypeConverter/tests/EnumConverterTest.cs
src/libraries/System.Private.CoreLib/src/System/RuntimeType.cs
src/libraries/System.Reflection/tests/TypeInfoTests.cs

index b604b1a52d91331add0d7124a983ffb0d681720d..c530786aa387969badc45bc335d8d8c2b53f24b4 100644 (file)
@@ -2396,9 +2396,8 @@ FCIMPL1(Object *, ReflectionEnum::InternalGetEnumUnderlyingType, ReflectClassBas
 
     VALIDATEOBJECT(target);
     TypeHandle th = target->GetType();
-    if (!th.IsEnum())
-        FCThrowArgument(NULL, NULL);
-
+    _ASSERTE(th.IsEnum());
+    
     OBJECTREF result = NULL;
 
     HELPER_METHOD_FRAME_BEGIN_RET_0();
index 9e071a1d587990b9d8bf6ad59cba95612b5d0469..1ba44811524dc67f69f6654af9d5a59fef05c887 100644 (file)
@@ -109,7 +109,7 @@ namespace System.ComponentModel.Tests
         public static void ConvertTo_WithContext_Negative()
         {
             AssertExtensions.Throws<ArgumentException>(null, () => EnumConverterTests.s_someEnumConverter.ConvertTo(TypeConverterTests.s_context, null, 3, typeof(string)));
-            AssertExtensions.Throws<ArgumentException>(null, "enumType", () => new EnumConverter(typeof(Enum)).ConvertTo(TypeConverterTests.s_context, null, SomeFlagsEnum.Option1, typeof(string)));
+            AssertExtensions.Throws<ArgumentException>("enumType", () => new EnumConverter(typeof(Enum)).ConvertTo(TypeConverterTests.s_context, null, SomeFlagsEnum.Option1, typeof(string)));
         }
 
         [Fact]
index 010ca6c2ce34ff6c0a953eb48b9e06226008e987..141826bc10e3cec013cca3ffcab8976ec32fc769 100644 (file)
@@ -237,6 +237,9 @@ namespace System
             if (value == null)
                 throw new ArgumentNullException(nameof(value));
 
+            if (!IsEnum)
+                throw new ArgumentException(SR.Arg_MustBeEnum, "enumType");
+
             // Check if both of them are of the same type
             RuntimeType valueType = (RuntimeType)value.GetType();
 
index 9d6d9fdbb88908e38f26f0f2060335c910ef542f..40c484c13381a8227d844a7a15b6e5edc61784fe 100644 (file)
@@ -471,10 +471,10 @@ namespace System.Reflection.Tests
         }
 
         [Fact]
-        [ActiveIssue("https://github.com/mono/mono/issues/15028", TestRuntimes.Mono)]
         public void IsEnumDefined_Invalid()
         {
-            AssertExtensions.Throws<ArgumentException>("", () => typeof(NonGenericClassWithNoInterfaces).GetTypeInfo().IsEnumDefined(10));
+            AssertExtensions.Throws<ArgumentException>("enumType", () => typeof(NonGenericClassWithNoInterfaces).GetTypeInfo().IsEnumDefined(10));
+            AssertExtensions.Throws<ArgumentException>("enumType", () => typeof(NonGenericClassWithNoInterfaces).GetTypeInfo().IsEnumDefined("10"));
             Assert.Throws<ArgumentNullException>(() => typeof(IntEnum).GetTypeInfo().IsEnumDefined(null));
             Assert.Throws<InvalidOperationException>(() => typeof(IntEnum).GetTypeInfo().IsEnumDefined(new NonGenericClassWithNoInterfaces()));
         }