Jarrell
Jarrell

Reputation: 31

System.PlatformNotSupportedException exception when calling Assembly.ReflectionOnlyLoadFrom

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)}

Upvotes: 3

Views: 4648

Answers (1)

Alon Fital
Alon Fital

Reputation: 31

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 :)

Upvotes: 0

Related Questions