Skip to content

Commit

Permalink
Fix empty ParamName in ArgumentException (dotnet#36208)
Browse files Browse the repository at this point in the history
* Update reflectioninvocation.cpp

* Update TypeInfoTests.cs

* Update EnumConverterTest.cs
  • Loading branch information
Youssef1313 authored May 11, 2020
1 parent 0ba41a8 commit d05a847
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
5 changes: 2 additions & 3 deletions src/coreclr/src/vm/reflectioninvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public static void ConvertTo_WithContext_Flags()
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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ public override bool IsEnumDefined(object value)
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();

Expand Down
4 changes: 2 additions & 2 deletions src/libraries/System.Reflection/tests/TypeInfoTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -471,10 +471,10 @@ public static void IsEnumDefined(object value, bool expected)
}

[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()));
}
Expand Down

0 comments on commit d05a847

Please sign in to comment.