我正在使用LoadFrom()加載dll,但由於某種原因,此加載函數不適用於所有dll,我想加載3000 dll以從每個dll獲取版權屬性。爲什麼reflection.assembly loadfile不加載所有dll?
我的代碼:
class ReverseDLL
{
private Assembly assembly;
private AssemblyDescriptionAttribute desc;
private AssemblyTitleAttribute title;
private AssemblyCopyrightAttribute copyRight;
public string getCopyright(string path)
{
try
{
//assembly = System.Reflection.Assembly.Load(System.IO.File.ReadAllBytes(path));
assembly = System.Reflection.Assembly.LoadFrom(path);//"C:\\Windows\\winsxs\\x86_microsoft.vc90.debugcrt_1fc8b3b9a1e18e3b_9.0.30729.1_none_bb1f6aa1308c35eb\\msvcm90d.dll");//path);// LoadFrom(path);
desc = (AssemblyDescriptionAttribute)
AssemblyDescriptionAttribute.GetCustomAttribute(
assembly, typeof(AssemblyDescriptionAttribute));
title = (AssemblyTitleAttribute)
AssemblyTitleAttribute.GetCustomAttribute(
assembly, typeof(AssemblyTitleAttribute));
copyRight = (AssemblyCopyrightAttribute)AssemblyCopyrightAttribute.GetCustomAttribute(assembly, typeof(AssemblyCopyrightAttribute));
}
catch
{
this.copyRight = new AssemblyCopyrightAttribute("");
}
if (this.copyRight == null)
this.copyRight = new AssemblyCopyrightAttribute("");
return copyRight.Copyright;
}
}
是否所有的dll管理dll? 「 – rkellerm 2010-07-18 08:08:55
」不起作用「並不是一份非常詳細的診斷報告......可能是由於您只是捕獲所有異常而沒有記錄發生了什麼事情。 (捕捉*這樣的一切*非常非常*很少是正確的事情。)失敗時有什麼例外? – 2010-07-18 08:14:54
您可以在捕獲異常時打印出堆棧跟蹤。很可能你會看到一些dll爲你的程序運行的東西而構建的(例如,試圖在x86上加載x64 dll,試圖加載本地dll而不是.NET程序集等) – nos 2010-07-18 11:57:59