我已经处理了AssemblyResolve
-event 但我仍然得到一个FileNotFoundException
. 我已经在类型初始化器中订阅了事件,并Assembly.LoadFrom
在Main
-method 中调用了该方法:
class Program
{
static Program()
{
AppDomain.CurrentDomain.AssemblyResolve+=new ResolveEventHandler(DeployAssemblyHandler);
}
static void Main(string[] args)
{
try
{
System.Reflection.Assembly asm=Assembly.LoadFrom("AxInterop.SHDocVw.dll");
}
catch(Exception)
{
}
}
public static System.Reflection.Assembly DeployAssemblyHandler(object sender,ResolveEventArgs args)
{
Assembly asm = null;
string asmName = new AssemblyName(args.Name).Name;
string deployAssemblyDirPath = ""; // Common.AppUtil.InstallDir + AppUtil.DeployedAssemblyDir;
string[] deployDirectories = Directory.GetDirectories(deployAssemblyDirPath);
foreach(string deploy in deployDirectories)
{
try
{
asm = Assembly.LoadFrom(deploy + "\\" + asmName);
break;
}
catch (Exception ex) { }
}
return asm;
}
}