Assembly查找過程

1.if(是共享程序集) 
      then 在GAC中搜索相應版本;

     私有程序集必須爲於應用程序所在目錄或子目錄中,而共享程序集安裝在被稱爲全局程序集緩存Global Assembly Cache,GAC)的一個特定的全局緩存中。在Windows操作系統中,GAC位於Windows系統目錄下的Assembly目錄中(例如:C:/WinNT/Assembly),另外注意,只有具備計算機管理員權限才能在GAC中安裝程序集。
     補充:共享程序集友好名稱與私有程序集一樣,但是.NET運行庫通過強名(strong name)(也稱共享名:shared name)來標識共享程序集。一個強名稱由友好名稱(如MathLibrary)、區域信息(如:英語)、版本號(如1.2.0.0)、公鑰(public key)和數字簽名等組成。

2.if(未找到)
    then 到應用程序的基目錄中;

3.if((未找到) && (應用程序的基目錄中有.config文件))
    then 到配置文件指定的位置搜索;

  e.g.(From《Microsoft.Net框架程序設計》):
  <?xml version="1.0" encoding="utf=8"?>
  <configuration>
     <runtime>
         <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <!-- 該元素的內容指示CLR在應用程序基目錄下的AuxFiles和bin/subdir子目錄中查找弱命名程序集。
           對於強命名程序集,CLR會在GAC中或者codeBase元素指定的RUL中查找。
    僅當沒有指定codeBase元素時,CLR纔會在應用程序的私有路徑下查找強命名程序集。-->
             <probing privatePath="AuxFiles;bin/subdir"/> <!--指定目錄,用分號隔開-->

             <dependentAssembly>
   <assemblyIdentity name="JeffTypes" publicKeyToken="……" culture="neutral"/>
   <bindingRedirect oldVersion="1.0.0.0" newVersion="2.0.0.0"/>
   <codeBase version="2.0.0.0" href="http://www.Wintellect.com/JeffTypes.dll"/>
      </dependentAssembly>

      <dependentAssembly>
   <assemblyIdentity name="FredTypes" publicKeyToken="……" culture="neutral"/>
   <bindingRedirect oldVersion="3.0.0.0-3.5.0.0" newVersion="4.0.0.0"/>
   <publisherPolicy apply="no"/>
      </dependentAssembly>
         </assemblyBinding>
     </runtime>
  </configuration>

4.if(未找到)
    then 引發異常,程序終止。
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章