IsValueType not set correctly for custom attribute fields of an enum type #941

Open
opened 2024-05-03 06:41:52 -05:00 by Zastai · 2 comments
Zastai commented 2024-05-03 06:41:52 -05:00 (Migrated from github.com)

All parts of the TypeReference for such an enum are right, it's just not flagged as a value type. As a result, using that TypeReference elsewhere results in load/resolve-time errors when using the modified assembly.

Looks like the reading for custom attribute fields/properties (AssemblyReader.ReadCustomAttributeFieldOrPropType) sees ElementType.Enum and then bases the TypeReference on the type name it finds.

All parts of the TypeReference for such an enum are right, it's just not flagged as a value type. As a result, using that TypeReference elsewhere results in load/resolve-time errors when using the modified assembly. Looks like the reading for custom attribute fields/properties (`AssemblyReader.ReadCustomAttributeFieldOrPropType`) sees ElementType.Enum and then bases the TypeReference on the type name it finds.
ltrzesniewski commented 2024-05-03 14:09:02 -05:00 (Migrated from github.com)

Hmm, this reminds me of something: github.com/ltrzesniewski/InlineIL.Fody@b257467995/src/InlineIL.Fody/Model/TypeRefBuilder.cs (L174-L181)

I wrote the following comment:

TypeRefs from different assemblies get imported as MetadataType.Class
since this information is not stored in the assembly metadata.

IIRC this applies to all value types, not only enums, since the TypeRef metadata table does not store this flag.

Hmm, this reminds me of something: https://github.com/ltrzesniewski/InlineIL.Fody/blob/b257467995801ee2f3a4db44aef86acfcceccbc9/src/InlineIL.Fody/Model/TypeRefBuilder.cs#L174-L181 I wrote the following comment: > TypeRefs from different assemblies get imported as MetadataType.Class > since this information is not stored in the assembly metadata. IIRC this applies to all value types, not only enums, since the `TypeRef` metadata table does not store this flag.
Zastai commented 2024-05-03 14:18:31 -05:00 (Migrated from github.com)

Yes, for the general case where there is just an utf8 type name to be resolved in the typeref table, that's understandable.

But here the ElementType adds that extra bit of information, because (afaik) all enums are value types.

Yes, for the general case where there is just an utf8 type name to be resolved in the typeref table, that's understandable. But here the ElementType adds that extra bit of information, because (afaik) all enums are value types.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-jbevain/cecil#941
No description provided.