-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Enum field type bug found when underlying type is set from assembly loaded with MLC #106375
Conversation
Tagging subscribers to this area: @dotnet/area-system-reflection-emit |
Should this runtime/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/TypeBuilderImpl.cs Lines 623 to 635 in f9c0846
this as well?
|
How did you find this issue? |
Does .NET Framework have this issue?
Is an alternative to override |
I would stay away from that. The problem with overriding Type.Equals is that it only works in one direction, it does not handle the case where |
Good point, I think we also need to add |
Found with #105903 |
.NET Framework and existing runtime EnumBuilder doesn't have this issue as there is no Core assembly logic, the Type equality check happens when trying to determine the core type from core assembly. runtime/src/libraries/System.Reflection.Emit/src/System/Reflection/Emit/ModuleBuilderImpl.cs Line 108 in bfd964a
I tried that, and exactly as @jkotas said it was not solving the issue completely |
8602793
to
b74cd2b
Compare
b74cd2b
to
902cd2f
Compare
/backport to release/9.0 |
Started backporting to release/9.0: https://github.com/dotnet/runtime/actions/runs/10411954784 |
EnumBuilder.UnderlyingSystemType
, currently returnsGetEnumUnderlyingType()
which returns_underlyingField.FieldType
underneath. Because Type.Equals checksUnderlyingSystemType
for equality when theEnumBuilder
underlying type is set from MLC Core assembly it is causing issue for enum fields defined, for example:In this case the
field
type should beTestEnum
, but it is evaluated to be equal toSystem.Int32
when writing the field signature on Save. I think we should not return underlying field type forEnumBuilder.UnderlyingSystemType
, should probably return the Enum itself instead (runtime enums returns the enum type itself). Though theEnumBuilder.GetEnumUnderlyingType()
method should keep returning the underlying field type.Related to #105903