我寫了一個自定義的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