私有程序集的探测过程

一段伪代码描述私有程序集的探测过程,摘自: TOM BARNABY 著的  《.NET 分布式编程》

          function ProbeForAssembly( AsmName, AppBase, Culture, PrivatePath)

// AsmName = The friendly name of the assembly, e.g., MathLibrary

// AppBase = Path where the requesting application resides

// Culture = The assembly reference culture, e.g., "En"

// PrivatePath = The list of  search paths specified  in the app config  file

 

// Search first for DLL extension  then EXE extension.

for each Ext in {"dll", "exe"}

Search( AppBase\AsmName.Ext )

 

if Culture == "neutral" Then

Search( AppBase\AsmName\AsmName.Ext )

else

Search( AppBase\Culture\AsmName.Ext )

Search( AppBase\Culture\AsmName\AsmName.Ext )

end if

 

// Search in all the paths specified  in the app config  file

for each Path in PrivatePath

if Culture == "neutral" Then

Search( AppBase\Path\AsmName.Ext )

Search( AppBase\Path\AsmName\AsmName.Ext )

else

Search( AppBase\Path\Culture\AsmName.Ext )

Search( AppBase\Path\Culture\AsmName\AsmName.Ext )

end if

next Path

next Ext

end function

 这里的AsmName指被引用的程序集的友好名,AppBase为当前应用程序所贮存的位置,

Culture为AsmName的语言文化信息,PrivatePath为AsmName所在的位置。

 

于C#中,可在AssemblyInfo.cs中,设置[assembly: AssemblyCulture("zh-CN")]来指定Culture信息,

默认(不指定)为neutral。 在App.config中,通过配置来指定PrivatePath.

私有程序集的探测过程 privatePath
 

整个probing的过程,伪代码已经描述的很清楚了,最好大家亲自验证下,以加深理解。我做了测试,整个

probing过程分毫不离于伪代码的描述的。这里要补充的一点:<codeBase>元素,当存在该元素时,

会跳至codeBase所指定的位置来加载指定名称的程序集的。

需要说明的:存在codeBase时,则不会再按如上描述的probing过程进行探测的,会优先进行codeBase的搜索。

且当程序集为非强名称的时候,codeBase指定的路径只能相对于当前路径的子目录(该情况下就无使用codeBase

的必要了); 强名称时,可为本机或网络的任意地方的。

私有程序集的探测过程 CodeBase

 

 

 

 

你可能感兴趣的:(程序)