创建一个新的应用程序域,设置 assemblyResolve 处理程序,你总是会得到一个异常,说“未找到程序集 [当前正在执行的程序集]”
是什么赋予了 ?代码如下
string _fileName = @"c:\temp\abc123.dll";
AppDomain sandBox = AppDomain.CreateDomain("sandbox");
sandBox.AssemblyResolve += new ResolveEventHandler(sandBox_AssemblyResolve);
// the line generates the exception !
System.Reflection.Assembly asm = sandBox.Load(System.Reflection.AssemblyName
.GetAssemblyName(fileName).FullName);
foreach (System.Reflection.AssemblyName ar in asm.GetReferencedAssemblies())
dbgWrite("Ref: " + ar.FullName );
System.Reflection.Assembly sandBox_AssemblyResolve
(object sender, ResolveEventArgs e)
{
System.Reflection.Assembly asm =
System.Reflection.Assembly.LoadFrom(_fileName);
return asm;
}
例外是:
System.IO.FileNotFoundException:无法加载文件或程序集“appAdmin,版本=1.0.0.0,文化=中性,PublicKeyToken=null”或其依赖项之一。该系统找不到指定的文件。文件名:'appAdmin,Version=1.0.0.0,Culture=neutral,PublicKeyToken=null' [snip]