Skip to content
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

Unable to set EntryPoint on generated assemblies with System.Reflection.Emit #62591

Open
masonwheeler opened this issue Dec 9, 2021 · 3 comments
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Reflection.Emit
Milestone

Comments

@masonwheeler
Copy link
Contributor

Background and motivation

In .NET Framework, System.Reflection.Emit.AssemblyBuilder had a SetEntryPoint method to define the EntryPoint of the generated assembly. In Core, that's no longer there. The EntryPoint property still exists, but there appears to be no way to set it.

While one might imagine that it's not needed without the ability to save generated assemblies -- and even with that ability it would be useless because .NET Core uses a different model where the entry point is in a specially-generated side EXE that loads up the generated DLL and runs Main on it -- this overlooks one important use case: REPLs/interpreters.

As it stands now, it's quite difficult to port an existing Reflection.Emit-based interpreter to .NET Core. Even if I work around this specific issue by adding an Attribute-based system to mark the entry point, the missing EntryPoint is still causing failures in hundreds of tests that look for it independent of the compiler/interpreter code.

API Proposal

Restore AssemblyBuilder.SetEntryPoint as it used to exist in .NET Framework.

API Usage

Same as in .NET Framework.

Alternative Designs

If there's a better way to set this up, that doesn't involve rewriting the entire codegen module to use something other that Reflection.Emit, I'd sure love to know about it!

Risks

Should be nonexistent. With no way to save generated assemblies, this would run no risk of creating assemblies that come out "the wrong way" for the .NET Core model. This change would essentially help interpreters and nothing else. (Of course, if AssemblyBuilder.Save ever gets added back in, this would need to be accounted for.)

@masonwheeler masonwheeler added the api-suggestion Early API idea and discussion, it is NOT ready for implementation label Dec 9, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added area-System.Reflection.Emit untriaged New issue has not been triaged by the area owner labels Dec 9, 2021
@ghost
Copy link

ghost commented Dec 9, 2021

Tagging subscribers to this area: @dotnet/area-system-reflection-emit
See info in area-owners.md if you want to be subscribed.

Issue Details

Background and motivation

In .NET Framework, System.Reflection.Emit.AssemblyBuilder had a SetEntryPoint method to define the EntryPoint of the generated assembly. In Core, that's no longer there. The EntryPoint property still exists, but there appears to be no way to set it.

While one might imagine that it's not needed without the ability to save generated assemblies -- and even with that ability it would be useless because .NET Core uses a different model where the entry point is in a specially-generated side EXE that loads up the generated DLL and runs Main on it -- this overlooks one important use case: REPLs/interpreters.

As it stands now, it's quite difficult to port an existing Reflection.Emit-based interpreter to .NET Core. Even if I work around this specific issue by adding an Attribute-based system to mark the entry point, the missing EntryPoint is still causing failures in hundreds of tests that look for it independent of the compiler/interpreter code.

API Proposal

Restore AssemblyBuilder.SetEntryPoint as it used to exist in .NET Framework.

API Usage

Same as in .NET Framework.

Alternative Designs

If there's a better way to set this up, that doesn't involve rewriting the entire codegen module to use something other that Reflection.Emit, I'd sure love to know about it!

Risks

Should be nonexistent. With no way to save generated assemblies, this would run no risk of creating assemblies that come out "the wrong way" for the .NET Core model. This change would essentially help interpreters and nothing else. (Of course, if AssemblyBuilder.Save ever gets added back in, this would need to be accounted for.)

Author: masonwheeler
Assignees: -
Labels:

api-suggestion, area-System.Reflection.Emit, untriaged

Milestone: -

@buyaa-n
Copy link
Contributor

buyaa-n commented Dec 14, 2021

We are considering adding support for AssemblyBuilder.Save which requirements also needs this API tagging @steveharter for further triage

@buyaa-n buyaa-n removed the untriaged New issue has not been triaged by the area owner label Dec 14, 2021
@buyaa-n buyaa-n added this to the 7.0.0 milestone Dec 14, 2021
@buyaa-n buyaa-n modified the milestones: 7.0.0, 8.0.0 Jul 6, 2022
@steveharter steveharter modified the milestones: 8.0.0, 9.0.0 Jul 24, 2023
@steveharter
Copy link
Member

Moving to 9.0; overlaps with AssemblyBuilder.Save() work.

@stephentoub stephentoub modified the milestones: 9.0.0, 10.0.0 Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-suggestion Early API idea and discussion, it is NOT ready for implementation area-System.Reflection.Emit
Projects
None yet
Development

No branches or pull requests

4 participants