【发布时间】:2015-02-23 22:52:51
【问题描述】:
假设我有一个主机/插件方案:
主持人:
static void Main(string[] args)
{
var path = @"D:\Plugin.dll";
var assembly = Assembly.LoadFile(path);
var type = assembly.GetType("Plugin.K");
var method = type.GetMethod("Run");
var instance = Activator.CreateInstance(type);
method.Invoke(instance, new object[] {});
}
插件:
public class K {
public void Run() {
// EXCEPTION THROWN HERE:
var x = Activator.CreateInstance("Plugin", "Plugin.K");
}
}
那为什么会抛出下面的异常呢?
An exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll but was not handled in user code
Additional information: Could not load file or assembly 'Plugin' or one of its dependencies. The system cannot find the file specified.
程序集不是已经加载到AppDomain中了吗?
【问题讨论】:
-
可能是路径问题?插件在哪里?
-
看起来很相似,或者被stackoverflow.com/questions/28684666/…欺骗了
-
从不使用 LoadFile(),总是使用 LoadFrom()。
-
@MichaelTodd 主机知道插件的路径,因为它调用“var assembly = Assembly.LoadFile(path);”。我想知道为什么框架不知道如何在插件本身中解决它。
标签: c# .net assemblies appdomain