我写了一个自定义的AssemblyResolve方法来处理exe文件以外的文件夹中的程序集。但一旦显示缺少“Microsoft.Practices.EnterpriseLibrary.Common.resources”。虽然我有Microsoft.Practices.EnterpriseLibrary.Common.dll,我没有Microsoft.Practices.EnterpriseLibrary.Common.resources.dll。我如何手动加载Microsoft.Practices.EnterpriseLibrary.Common.resources?AppDomain AssemblyResolve事件要求Microsoft.Practices.EnterpriseLibrary.Common.resources
protected Assembly ConfigResolveEventHandler(object sender, ResolveEventArgs args)
{
//This handler is called only when the common language runtime tries to bind to the assembly and fails.
//Retrieve the list of referenced assemblies in an array of AssemblyName.
string strTempAssmbPath = "";
Assembly asm = this.GetType().Assembly;
var uri = new Uri(Path.GetDirectoryName(asm.CodeBase));
Assembly objExecutingAssemblies = Assembly.GetExecutingAssembly();
AssemblyName[] arrReferencedAssmbNames = objExecutingAssemblies.GetReferencedAssemblies();
//Loop through the array of referenced assembly names.
if (arrReferencedAssmbNames.Any(strAssmbName => strAssmbName.Name == args.Name))
{
strTempAssmbPath = Path.Combine(uri.LocalPath, args.Name) + ".dll";
}
//Load the assembly from the specified path.
Assembly myAssembly = Assembly.LoadFrom(strTempAssmbPath);
//Return the loaded assembly.
return myAssembly;
}
我遇到了同样的问题,但我不相信它实际上是一个存在的DLL。 “Microsoft.Practices.EnterpriseLibrary.Common.dll”库中附带有资源,可能出于某种原因无法访问这些资源。在.NET Reflector中查看它,它列出了引用,并且未列出“Microsoft.Practices.EnterpriseLibrary.Common.resources.dll”。你有没有运气呢? – merthsoft 2011-04-27 22:00:05