调用Assembly.ReflectionOnlyLoadFrom时发生System.PlatformNotSupportedException异常

时间:2019-01-29 17:49:33

标签: c# assembly.reflectiononly

我正在使用.NET Core 2.1加载调用Assembly.ReflectionOnlyLoadFrom(...)的程序集,但遇到System.PlatformNotSupportedException异常。 Microsoft documentation似乎表明它应该工作。实施了吗?如果没有,是否有其他方法可以使用.NET Core从.NET 4.7.2程序集获取导出的类型?

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 个答案:

答案 0 :(得分:0)

如上所述,.net内核尚不支持反射。 您可以从LAB的存储库中使用实验性的 TypeLoader

如果要使用实验性NuGet,则需要遵循以下说明: https://github.com/dotnet/corefxlab(基本上添加了NuGet存储库-https://dotnet.myget.org/F/dotnet-corefxlab/)并获取System.Reflection.TypeLoader。

虽然期望不高:)

相关问题