【发布时间】:2015-02-16 08:20:54
【问题描述】:
我正在尝试将程序集加载到单独的应用程序域中。 我不想创建任何实例或执行程序集。所以我没有使用 CreateInstanceAndUnwrap 方法。我只想加载 dll 文件(不从中创建任何类型等)
var cat = new AggregateCatalog();
pluginApplicationDomain = AppDomain.CreateDomain("pluginApplicationDomain", AppDomain.CurrentDomain.Evidence,
appDomainInfo);
cat.Catalogs.Add(new AssemblyCatalog(pluginApplicationDomain.Load(File.ReadAllBytes(plugin))));
plugin 是 dll 文件的相对路径。
../../Extensions/Plugins\MyAssembly.dll
这会抛出“System.IO.FileNotFoundException”
路径是正确的,如果我做Assembly.LoadFrom(plugin),它不会抛出任何异常,所以我猜不是路径不正确。
其他解决方案都使用CreateInstanceAndUnwrap,但是如果程序集及其类型对我来说是黑盒怎么办?我知道它会影响一个界面,仅此而已?
Load dll into another domain exception
这行得通吗?但是我的方法的签名与CrossAppDomainDelegate中的签名不匹配
【问题讨论】:
-
你想达到什么目的,我的意思是,你为什么需要将程序集加载到单独的域?
-
因为它是一个插件,所以我想把它加载到一个单独的域中,因为如果插件崩溃,主应用程序不会,因为它在不同的域中。