在 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(不起作用)