runtime icon indicating copy to clipboard operation
runtime copied to clipboard

How can I do Assembly.ReflectionOnlyLoad in the .net core

Open hongdai opened this issue 9 years ago • 10 comments

I would like to do reflection only load, does not need to instantiate. How can I do it in .Net Core?

hongdai avatar Feb 16 '17 03:02 hongdai

ReflectionOnlyLoads are not available in .NET Core. The recommended replacement is System.Reflection.Metadata.

What are you using reflection only loads for?

jkotas avatar Feb 16 '17 03:02 jkotas

We use it to get all public types and properties in an assembly.

System.Reflection.Metadata should work. However, since we use Assembly interface in the legacy product, it will be major code changes to change from Full framework to .Net Core. To help customers migrate from existing applications, it will be great that you can support the existing API.

hongdai avatar Feb 16 '17 05:02 hongdai

We will need to construct Type object from the metadata, and compare to the Type information serialized from a full framework service. Is there a reliable way to do it?

hongdai avatar Feb 16 '17 05:02 hongdai

You can compare type name and maybe assembly name, depends on what you are trying to do. Note the type assemblies are different in .NET Core.

jkotas avatar Feb 16 '17 06:02 jkotas

We will have to look for how the type object are used in the existing code all over the places and ensure we don't miss one.

I've tried to fully load the assembly and the Type object I've got from the assembly works. However, we cannot fully load the assembly in our real customer scenario.

Supporting ReflectionOnlyLoad will make the migration much easier.

hongdai avatar Feb 16 '17 06:02 hongdai

This would help that but I doubt it'll happen in the near future https://github.com/dotnet/corefx/issues/2800

davidfowl avatar Feb 16 '17 07:02 davidfowl

cc @AtsushiKan

jkotas avatar Feb 16 '17 07:02 jkotas

CC @AlexGhiondea

gkhanna79 avatar Mar 04 '17 19:03 gkhanna79

Let's use https://github.com/dotnet/corefx/issues/2800 to track this

jkotas avatar Mar 04 '17 20:03 jkotas

tl;dr https://github.com/dotnet/corefxlab/blob/master/docs/specs/typeloader.md

IanKemp avatar Jan 29 '19 18:01 IanKemp