c# - 将 .dll 加载到单独的应用程序域 (MEF)

标签 c# .net dll mef

我正在尝试将程序集加载到单独的应用程序域中。 我不想创建任何实例或执行程序集。所以我没有使用 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

之一不匹配

最佳答案

MEF 更多的是关于可扩展性,看起来您实际上正在寻找 [MAF] 1 .看看这个 SO question .根据我的个人经验,如果您的插件要调用一些 native 代码(例如与硬件交互),AppDomains 将无法防止崩溃。在 separate processes 中托管此类插件更安全.

关于c# - 将 .dll 加载到单独的应用程序域 (MEF),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28537154/

相关文章:

c# - 使用 C# 启用 RabbitMQ 管理插件

c# - FindAll 具有不同相关性的条件

dll - 如何在 SQLFiddle 中加载 SQLite 的扩展?

c# - 从内存中卸载 DLL

.net - 为什么 Console.ReadKey() 会阻止在另一个线程中调用的 Console.WriteLine 的输出?

pythonnet 无法从 vb .net dll 调用方法 - TypeError

c# - C# .Net 上 MySQL 查询中的特殊字符

c# - 具有永久ShellExec连接的SharpSSH

.net - 构建 'flat'而不是 'tree' LINQ表达式

c# - 如何使用 Azure TableClient 2.0 BeginExecuteQuerySegmented