如何在应用平台之外装载程序集(详细信息) [英] How to load assemblies outside the appbase(more information)

查看:113
本文介绍了如何在应用平台之外装载程序集(详细信息)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何加载哪些是应用平台和应用程序域之外的组件。

我的问题是,我是上的共享目录组件列表。我的应用程序需要加载这些程序集,它位于应用平台(可执行文件路径)指定的路径之外。我不想将它们移到应用平台文件夹。

有关详细信息,我这是运行在分布式域测试组件的集合的应用程序。当应用程序启动时,它加载从一个数组这些组件。当我测试我的本地桌面上的这个应用程序,它工作得很好(负载,并从组件等反射),但是从群集计算机,它不能加载这些相同的组件,并抛出以下异常:

  

FileNotFoundException异常。无法加载文件或程序集或它的一个依赖。该系统找不到指定的文件。

解决方案

怎么样的 MSDN - 集加载文件

 字符串文件路径=C:\ asmPath;
大会MyAssembly程序= Assembly.LoadFile(文件路径);
 

您还可以定义你的app.config探测路径(我认为更好的解决方案),并具有加载CLR按需装配。 MSDN探测

路径

 <结构>
   <运行>
      < assemblyBinding的xmlns =瓮:架构 - 微软COM:asm.v1>
         <探测privatePath =斌; BIN2 \ subbin; BIN3/>
      < / assemblyBinding>
   < /运行>
< /结构>
 

I want to know how to load assemblies which are outside the Appbase and Appdomain.

My problem is that I have a list of assemblies that are on a shared directory. My application needs to load these assemblies, which are located outside the path specified in the Appbase (path to the executable). I do not want to move them into the Appbase folder.

For more information, I have an application which is running in a distributed domain to test a collection of assemblies. When the application starts, it loads these assemblies from an array. When I test this application on my local desktop, it works well (loads and make reflection from assemblies, etc.), but from the cluster computers, it can't load those same assemblies, and throws the following Exception:

FileNotFoundException. Could not load file or assembly or one of its dependencies. The system cannot find the file specified.

解决方案

What About MSDN - Assembly Load File

string filePath = "C:\asmPath";
Assembly myAssembly = Assembly.LoadFile(filePath);

You can also define a probe path in your app.config (which I consider a better solution) and having the CLR loading the assemblies on demand. MSDN Probing Path

<configuration>
   <runtime>
      <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
         <probing privatePath="bin;bin2\subbin;bin3"/>
      </assemblyBinding>
   </runtime>
</configuration>

这篇关于如何在应用平台之外装载程序集(详细信息)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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