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 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.
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.FieldTypeunderneath. Because Type.Equals checksUnderlyingSystemTypefor equality when theEnumBuilderunderlying type is set from MLC Core assembly it is causing issue for enum fields defined, for example:In this case the
fieldtype should beTestEnum, but it is evaluated to be equal toSystem.Int32when 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