Fix Mono RuntimeType to handle conversion between enums of same underlying type....
authorJohan Lorensson <lateralusx.github@gmail.com>
Fri, 17 Jul 2020 13:32:21 +0000 (15:32 +0200)
committerGitHub <noreply@github.com>
Fri, 17 Jul 2020 13:32:21 +0000 (15:32 +0200)
runtime\src\tests\tracing\common\TraceConfiguration.cs tries to call
a constructor of using type System.Diagnostics.Tracing.EventPipeSerializationFormat
with a different (but compatbile) enum type using reflection. Both enums
are of underlying type, Int32, but the call fails on Mono since it fails
to recognize that the two enums are compatible in CheckValue.

Fix will make sure call to IsConvertibleToPrimitiveType uses underlying
type as target type when checking if current value is convertible to a
compatible value.

src/mono/netcore/System.Private.CoreLib/src/System/RuntimeType.Mono.cs

index 0bfb8fcde9e723ea92236da7235ab63c10e2b626..c665878637c35e9bcc70e03eaee7fb0d6174c2c2 100644 (file)
@@ -2002,7 +2002,7 @@ namespace System
                 Type? type = Enum.GetUnderlyingType(this);
                 if (type == value.GetType())
                     return value;
-                object? res = IsConvertibleToPrimitiveType(value, this);
+                object? res = IsConvertibleToPrimitiveType(value, type);
                 if (res != null)
                     return res;
             }