我正在使用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