Skip to content

System.Reflection.MetadataLoadContext doesn't support function pointer types #43791

Closed

Description

@vargaz

To reproduce: run the attached project
Version: master
Expected result: works
Actual result:

Unhandled exception. System.NotSupportedException: Parsing function pointer types in signatures is not supported.
   at System.Reflection.TypeLoading.Ecma.EcmaModule.GetFunctionPointerType(MethodSignature`1 signature)
   at System.Reflection.Metadata.Ecma335.SignatureDecoder`2.DecodeType(BlobReader& blobReader, Boolean allowTypeSpecifications, Int32 typeCode)
   at System.Reflection.Metadata.Ecma335.SignatureDecoder`2.DecodeMethodSignature(BlobReader& blobReader)
   at System.Reflection.TypeLoading.Ecma.EcmaMethodDecoder.SpecializeMethodSig(IRoMethodBase roMethodBase)
   at System.Reflection.TypeLoading.RoDefinitionMethod`1.ComputeMethodSig()
   at System.Reflection.TypeLoading.RoMethod.get_MethodSig()
   at System.Reflection.TypeLoading.RoMethod.get_ReturnParameter()
   at System.Reflection.TypeLoading.RoMethod.get_ReturnType()

Activity

  1. vargaz commented on Oct 24, 2020

    @vargaz
    ContributorAuthor
  2. marek-safar commented on Oct 24, 2020

    @marek-safar
    Contributor

    Hmm how is Roslyn reading such metadata?

    @jaredpar @MichalStrehovsky

  3. MichalStrehovsky commented on Oct 24, 2020

    @MichalStrehovsky
    Member

    This looks like a bug in System.Reflection.MetadataLoadContext. It's a library built on top of System.Reflection.Metadata that provides additional abstractions over the metadata. Roslyn only uses S.R.Metadata, not this extra layer with the missing implementation.

  4. added this to the 6.0.0 milestone on Nov 11, 2020
  5. added
    enhancementProduct code improvement that does NOT require public API changes/additions
    and removed
    untriagedNew issue has not been triaged by the area owner
    on Nov 11, 2020
  6. self-assigned this
    on Nov 11, 2020
  7. steveharter commented on Nov 12, 2020

    @steveharter
    Contributor

    This looks like a bug in System.Reflection.MetadataLoadContext

    It is apparently by design since it throws an explicit NotSupportedException when detecting a function pointer.

    This overlaps with #11354 where we don't return function pointer type from standard reflection either and need a way to represent that.

    Doing a typeof(delegate*<void>) (for example) returns System.IntPtr as the type, so it would be expected that MLC return IntPtr as the type. However, that doesn't allow inspection of the parameters or return type, and there is not an existing "function pointer" type in .NET that we can readily use instead.

  8. steveharter commented on Nov 12, 2020

    @steveharter
    Contributor

    @vargaz @CoffeeFlux can you add more detail including the workaround you use, and the "blocking" label if you consider it blocking. Thanks

  9. 16 remaining items

  10. lambdageek commented on Jun 22, 2022

    @lambdageek
    Member

    @steveharter Will the #69273 MetadataLoadContext work also happen in 7? Will that include also the .NET Framework version of MLC? If so, that will help us with this issue with the wasm tooling.

  11. steveharter commented on Jul 6, 2022

    @steveharter
    Contributor

    @lambdageek yes MetadataLoadContext will be updated along with the CoreClr runtime. The active PR is #71516.

    It should be possible to use .NET framework with MetadataLoadContext function pointers although reflection will necessary to call the new APIs on Type. I'll provide an example once that PR is in.

  12. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Jul 6, 2022
  13. jkotas commented on Jul 11, 2022

    @jkotas
    Member

    It should be possible to use .NET framework with MetadataLoadContext function pointers although reflection will necessary to call the new APIs on Type. I'll provide an example once that PR is in.

    We may want to provide extension methods so that it is not necessary to use reflection.

  14. steveharter commented on Jul 13, 2022

    @steveharter
    Contributor

    Moving to 8.0; we need to update the API and design based on feedback from #71516.

  15. modified the milestones: 7.0.0, 8.0.0 on Jul 13, 2022
  16. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Jul 13, 2022
  17. ghost added
    in-prThere is an active PR which will close this issue when it is merged
    on Jan 24, 2023
  18. ghost removed
    in-prThere is an active PR which will close this issue when it is merged
    on Feb 16, 2023
  19. ghost locked as resolved and limited conversation to collaborators on Mar 19, 2023
  20. added
    in-prThere is an active PR which will close this issue when it is merged
    on Apr 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-System.ReflectionenhancementProduct code improvement that does NOT require public API changes/additionsin-prThere is an active PR which will close this issue when it is merged

Type

No type

Projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions