2
votes

I am using .NET Core 2.1 to load an assembly calling Assembly.ReflectionOnlyLoadFrom(...) but am getting a System.PlatformNotSupportedException exception. Microsoft documentation seems to indicate that it should work. Has this been implemented? If not, are there any alternatives to get exported types from a .NET 4.7.2 assembly using .NET Core?

Assembly.ReflectionOnlyLoadFrom(fileName)
'Assembly.ReflectionOnlyLoadFrom(fileName)' threw an exception of type 'System.PlatformNotSupportedException'
    Data: {System.Collections.ListDictionaryInternal}
    HResult: -2146233031
    HelpLink: null
    InnerException: null
    Message: "ReflectionOnly loading is not supported on this platform."
    Source: "System.Private.CoreLib"
    StackTrace: "   at System.Reflection.Assembly.ReflectionOnlyLoadFrom(String assemblyFile)"
    TargetSite: {System.Reflection.Assembly ReflectionOnlyLoadFrom(System.String)}
1
It looks like there's a known issue on the documentation GitHub. - Joe Sewell
@JoeSewell Just found that one too. - Ian Kemp
According to github.com/dotnet/corefxlab/blob/master/docs/specs/… you should look at System.Reflection.TypeLoader. - Ian Kemp
@IanKemp And where is that class to be found? Can't access it in .NET Core 3 targets. - Ray

1 Answers

0
votes

As written above, reflection is not supported yet on .net core. You can use the experimental use TypeLoader from the LAB's repo.

If you want to use the experimental NuGets, you need to follow instructions on: https://github.com/dotnet/corefxlab (basically adding the NuGet repo - https://dotnet.myget.org/F/dotnet-corefxlab/) and fetch the System.Reflection.TypeLoader.

Don't expect much support though :)