如何在应用平台之外装载程序集(详细信息)详细信息、程序、如何在、平台

2023-09-04 00:22:28 作者:圈子不同别硬碰

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

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

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

  

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

解决方案

怎么样的 MSDN - 集加载文件

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

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

路径

 <结构>
   <运行>
      < assemblyBinding的xmlns =瓮:架构 - 微软COM:asm.v1>
         <探测privatePath =斌; BIN2 \ subbin; BIN3/>
      < / assemblyBinding>
   < /运行>
< /结构>
 
C 应用程序如何载入窗口2

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>