Euc*_*lid 4 c# reflection dll exception
如何检查加载的程序集是否是有效的.NET程序集?我目前有这个代码,但非托管DLL抛出BadImageFormatException.
string[] filepaths = Directory.GetFiles(Directory.GetCurrentDirectory(), "*.dll", SearchOption.AllDirectories);
List<Type> potentialEffects = new List<Type>();
foreach (string filepath in filepaths)
{
Assembly a = Assembly.LoadFile(filepath);
potentialEffects.AddRange(a.GetTypes());
}
Run Code Online (Sandbox Code Playgroud)
Seb*_*ter 11
你可以简单地抓住这个例外吗?
另请参阅此文章:http://blogs.msdn.com/suzcook/archive/2004/03/17/determining-whether-a-file-is-an-assembly.aspx 抓住异常.检查比假设文件是有效程序集要昂贵得多.
| 归档时间: |
|
| 查看次数: |
1665 次 |
| 最近记录: |