Skip to content

Add back Reflection.Emit APIs from .NET Framework #49452

Closed

Description

@eerhardt

As a follow up to #46681 and #49319, I looked at the rest of the APIs that were missing from Reflection.Emit:

Compat issues with assembly System.Reflection.Emit:
MembersMustExist : Member 'public System.Reflection.Emit.ModuleBuilder System.Reflection.Emit.AssemblyBuilder.DefineDynamicModule(System.String, System.Boolean)' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.Reflection.Module System.Reflection.Emit.ConstructorBuilder.GetModule()' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.String System.Reflection.Emit.ConstructorBuilder.Signature.get()' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.Reflection.Module System.Reflection.Emit.MethodBuilder.GetModule()' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.String System.Reflection.Emit.MethodBuilder.Signature.get()' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.Diagnostics.SymbolStore.ISymbolDocumentWriter System.Reflection.Emit.ModuleBuilder.DefineDocument(System.String, System.Guid, System.Guid, System.Guid)' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'protected System.ModuleHandle System.Reflection.Emit.ModuleBuilder.GetModuleHandleImpl()' does not exist in the reference but it does exist in the implementation.
MembersMustExist : Member 'public System.Boolean System.Reflection.Emit.ModuleBuilder.IsTransient()' does not exist in the reference but it does exist in the implementation.
Total Issues: 8

The following APIs don't exist (and shouldn't) in .NET Core because we don't support saving the generated assembly to disk. (#15704)

  • AssemblyBuilder.DefineDynamicModule
  • ModuleBuilder.DefineDocument

The following API is because of an implementation detail, and doesn't need to be exposed since it has never been exposed:

  • ModuleBuilder.GetModuleHandleImpl (See the code comment for an explanation)

That leaves the following APIs to be decided if we should bring them back:

  • Module ConstructorBuilder.GetModule
  • Module MethodBuilder.GetModule
  • string ConstructorBuilder.Signature
  • string MethodBuilder.Signature
  • bool ModuleBuilder.IsTransient
  1. The Signature properties seem pretty simple. They return a string represenation of the signature of the method.

  2. The GetModule() methods are interesting because these types already have a Module property on them. Looking at the code, the GetModule() method and the Module property don't have the same code, but eventually return the same thing - the module of the type containing this Method.

  3. I'm not exactly sure what IsTransient means, and the MSDN doc doesn't give a good explanation.

Returns a value that indicates whether this dynamic module is transient.

Looking at the code, on mono it always returns true. On coreclr, it calls into the native runtime, and the only place I can see setting the flag, always sets it to true as well.

m_pManifest = ReflectionModule::Create(this, GetManifestFile(), pamTracker, REFEMIT_MANIFEST_MODULE_NAME, TRUE);


So I guess after all that, the only API I'd recommend adding back is the ConstructorBuilder.Signature and MethodBuilder.Signature properties. I don't think we need to add the other missing APIs.

Activity

  1. added
    api-suggestion
    on Mar 10, 2021
  2. ghost added
    untriaged
    on Mar 10, 2021
  3. jkotas commented on Mar 10, 2021

    @jkotas
    Member

    We have said that we are done with bringing back APIs from .NET Framework. If we want to add these APIs, they should be reviewed as brand new additions.

  4. jkotas commented on Mar 10, 2021

    @jkotas
    Member

    Looks like the APIs on the list are public in the implementation, but missing in the ref file. I think we should just mark them private/internal in the implementation, or delete them if they are not actually used.

  5. added this to the 6.0.0 milestone on May 12, 2021
  6. removed
    untriaged
    on May 12, 2021
  7. buyaa-n commented on May 12, 2021

    @buyaa-n
    Contributor

    So I guess after all that, the only API I'd recommend adding back is the ConstructorBuilder.Signature and MethodBuilder.Signature properties. I don't think we need to add the other missing APIs.

    @eerhardt are you OK with just removing the implementation of those APIs as @jkotas suggested (I choose to remove them because I don't see they are actually used). If you are OK with that i am gonna remove the api-suggestion label and mark it up-for-grubs. Or do you still want to add an API proposal to add them in ref and go through API review?

  8. eerhardt commented on May 12, 2021

    @eerhardt
    MemberAuthor

    I'm 100% fine with removing the implementation. If we made it this long without someone complaining, they must not be necessary. We can always add them in the future if someone does find a need for them.

  9. added
    good first issue
    help wanted
    and removed
    api-suggestion
    on May 12, 2021
  10. added a commit that references this issue on Jul 22, 2021
    0070eff
  11. ghost added
    in-pr
    on Jul 22, 2021
  12. i3arnon commented on Jul 22, 2021

    @i3arnon
    Contributor

    I can take this if that's fine.
    I made a PR removing the unused code.
    I'm not sure how to generate the RefApiCompatBaseline though..

  13. KalleOlaviNiemitalo commented on Jul 24, 2021

    @KalleOlaviNiemitalo

    I'm not exactly sure what IsTransient means

    According to the AssemblyBuilder.DefineDynamicModule docs, the methods that have a string fileName parameter define a persistable module, and the methods without this parameter define a transient module. AssemblyBuilder.Save then "saves all non-transient dynamic modules".

  14. added a commit that references this issue on Jul 29, 2021
    742ea07
  15. ghost removed
    in-pr
    on Jul 29, 2021
  16. ghost locked as resolved and limited conversation to collaborators on Aug 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.Reflection.Emitgood first issuehelp wanted

    Type

    No type

    Projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions