Skip to content

EnumBuilder.UnderlyingSystemType != EnumBuilder.CreateType().UnderlyingSystemType #110924

Open
@DanielBThayer

Description

Description

When creating an enumeration via the DefineEnum on the ModuleBuilder, the emitted type's UnderlyingSystemType is set to the type being emitted (creating a circular reference path). It should be set to the provided type.

Reproduction Steps

ModuleBuilder _moduleBuilder = AssemblyBuilder.DefineDynamicAssembly(new AssemblyName("Test"), AssemblyBuilderAccess.RunAndCollect).DefineDynamicModule("Test");

EnumBuilder builder = _moduleBuilder.DefineEnum("E_Test", TypeAttributes.Public, typeof(int));

builder.DefineLiteral("Low", 0);
builder.DefineLiteral("High", 1);

Type type = builder.CreateType();

if (type.UnderlyingSystemType == type)
{
throw new Exception("Circular reference");
}
else if (type.UnderlyingSystemType != builder.UnderlyingSystemType)
{
throw new Exception("This should never throw");
}

Expected behavior

Emitted type has the underlying type set to the type defined in the DefineEnum call ("Circular reference" exception will be thrown)

Actual behavior

Emitted type has the underlying type set to itself

Regression?

No response

Known Workarounds

No response

Configuration

.Net version: .Net 8.0.11
OS: Windows 11, latest updates applied
Arch: x64

System.Reflection: 4.3.0

Other information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    area-System.Reflection.Emitbreaking-changeIssue or PR that represents a breaking API or functional change over a prerelease.bughelp wanted[up-for-grabs] Good issue for external contributors

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions