【发布时间】:2019-03-14 13:50:54
【问题描述】:
我在 Visual Studio 2017 中有 2 个解决方案。
- 第一个解决方案有一个项目,该项目从外部解决方案的项目中读取程序集/dll。该项目使用 .net 4.5.2 编码
- 第二个解决方案有一个项目,该项目带有目标类/dll 以反映到第一个项目。这个项目是用 .net core 2 编写的
- 这两个项目都有两种不同的解决方案。
第一个项目中的代码:
string pathDllProject_DAL = "E:\\Coding\\Repos\\_order_manager_webapp\\order_manager_webapp_backend\\DAL\\bin\\Debug\\netcoreapp2.2\\DAL.dll";
//This line of code works, I do get the assembly object
Assembly ass_DAL2 = Assembly.LoadFile(pathDllProject_DAL);
Type[] respTypes = ass_DAL2.GetTypes(); //<----Exception Thrown HERE
这是我得到的例外:
'ass_DAL2.GetTypes()' threw an exception of type 'System.Reflection.ReflectionTypeLoadException'
Data: {System.Collections.ListDictionaryInternal}
HResult: -2146232830
HelpLink: null
InnerException: null
LoaderExceptions: {System.Exception[152]}
Message: "Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information."
Source: "mscorlib"
StackTrace: " at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)\r\n at System.Reflection.RuntimeModule.GetTypes()\r\n at System.Reflection.Assembly.GetTypes()"
TargetSite: {System.RuntimeType[] GetTypes(System.Reflection.RuntimeModule)}
Types: {System.RuntimeType[279]}
我想知道从 .net 4.5.2 框架读取在 .net-core 中创建的 DLL 是否不兼容?还是有其他问题?
【问题讨论】:
-
Retrieve the LoaderExceptions property for more information.你这样做了吗? -
@thehennyy 是否提示从dll中加载的类型数据不兼容?
-
那么这就是你的答案。
-
@thehennyy 所以唯一的解决方案是将 Dll 阅读器项目重写为 .net.core 项目?
-
这取决于您的用例。有一个库可以读取这两种类型的文件,但是它们包含的代码是不可执行的。看看
dnlib。
标签: c# .net reflection .net-core