Md.*_*rim 3 c# dll dllimport dll-injection dynamic-dll-import
在 C# 中,当尝试获取类型时,使用下面的代码从文件夹加载 DLL,获取下面的堆栈跟踪。
var assembly = Assembly.LoadFile(assemblyInfo.FullName); // assembly loads perfectly using the absolute path.
var types = assembly.GetTypes(); // this line throws the below stacktrace.
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪:
System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
at System.Reflection.Assembly.GetTypes()
Run Code Online (Sandbox Code Playgroud)
我还检查了现有的解决方案:错误消息“无法加载一种或多种请求的类型”。检索 LoaderExceptions 属性以获取更多信息。,在 C# 中运行时加载 DLL(不起作用)
问题的解决非常简单。它只是使用了与装配不同的方法。LoadFile我们应该使用而不是使用LoadFrom
所以下面的代码有效地解决了这个问题
var assembly = Assembly.LoadFrom(assemblyInfo.FullName); // loads perfectly, absolute path to dll
var types = assembly.GetTypes(); // loads perfectly.
Run Code Online (Sandbox Code Playgroud)
无需使用 GetExportedTypes。我们可以获得所有类型。
LoadFrom 与其他 DLL 进行自动反射绑定,但是 loadfile 不会执行相同的操作。
这解决了出口问题。
| 归档时间: |
|
| 查看次数: |
10863 次 |
| 最近记录: |