问题动态加载组件的依赖关系在运行时 [英] Problems loading assembly dependencies dynamically at run-time

查看:143
本文介绍了问题动态加载组件的依赖关系在运行时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我试着解释我的问题。我目前正在开发一个小插件骨架.NET编写(主要用于试验了一下)。这样的想法是有哪个插件可以通过部署动态链接库中的特定文件夹的主应用程序的插件中添加一个主应用程序。 一切工作正常,该插件是正确实例,但是现在我面临的一个问题。 我现在已经部署了一个使用额外的第三方插件,因此现在我有一个由X需要这些额外的第三方插件都没有发现在运行时的问题插件的X。因此,我的想法是,现在增加一个额外的目录下的依赖性,我也部署所有需要的插件。

let me try to explain my problem. I'm currently trying to develop a small "plugin-framework" written in .Net (mainly for experimenting a bit). So the idea is to have a main application to which "plugins" can be added by deploying dlls in a specific folder "plugins" of the main application. Everything works fine, the plugins are instantiated properly, however now I'm facing a problem. I have deployed now a plugin "X" that uses additional 3rd-party plugins and so now I have the problem that these additional 3rd-party plugins required by "X" are not found at run-time. My idea is therefore now to add an additional directory "dependencies" where I also deploy all of the needed plugins.

所以我的第一个问题: 我怎样才能加载组件到应用程序域(因为我知道路径它们)ST他们可以使用我的应用程序?

So my first question: How can I load the assemblies into the application domain (given that I know the path to them) s.t. they can be used by my application?

我试图接近,通过做一些这样的:

I tried to approach that by doing something like:

AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve);

System.Reflection.Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
    //find the path to the assembly and then load and return it by
    //return Assembly.Load("pathToDependencies/failedAssembly.dll");
}

现在的问题是,这个事件处理程序,现在被激活具有args变量的presentation.Zune.dll(我使用的一个WPF应用程序)。看来,如果该程序集加载失败,但实际问题是另一个DLL。

The problem is that this event-handler now gets activated having the "Presentation.Zune.dll" in the args variable (I'm using a WPF app). It seems as if that assembly failed loading but the actual problem is another dll.

有人建议我一个更好的办法来解决我的问题?我希望我能够充分解释我的情况,否则只是要求进一步澄清。

Can someone suggest me a better way to solve my problem? I hope that I was able to explain my situation sufficiently, otherwise just ask for further clarification.

谢谢, 树里

推荐答案

您可以设置运行时的探测路径,以便它可以找到程序集。设置探测在你的应用程序的配置文件元素。

You can set the probing path of the runtime so it can find the assemblies. Set the probing element in your apps config file.

<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <probing privatePath="plugins;dependencies"/>
    </assemblyBinding>
  </runtime>
</configuration>

这篇关于问题动态加载组件的依赖关系在运行时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆