Application_Start
我有一个库模块,我们在所有 Web 应用程序中都使用它,它以 ASP.NET Webforms 应用程序的方法将所有加载的程序集(及其版本号)列出到我们的 log4net 日志文件中。
这已经完美运行了很长时间 - 直到今天,当我尝试在“应用程序预热”方法之后使用它时(Scott Guthrie 在他的博客文章中描述了在部署到 IIS 之后运行(并且在ASP.NETApplication_Start
运行之前) - 现在突然我收到一个错误:
System.NotSupportedException:动态程序集中不支持调用的成员。
报告已加载程序集的代码如下所示:
public static void ReportLoadedAssemblies(this ILog log)
{
if (log.IsInfoEnabled)
{
log.Info("Loaded assemblies:");
IEnumerable<Assembly> appAssemblies = AppDomain.CurrentDomain.GetAssemblies().OrderBy(c => c.ManifestModule.Name);
foreach (Assembly asm in appAssemblies)
{
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(asm.Location);
if (!fvi.CompanyName.Contains("Microsoft"))
{
log.Info(String.Format("{0, -45} : {1, -15} {2}", fvi.FileDescription, fvi.FileVersion, asm.Location));
}
}
}
}
我不是 100% 清楚哪一行会引发错误——我怀疑是这个:
IEnumerable<Assembly> appAssemblies = AppDomain.CurrentDomain.GetAssemblies().OrderBy(c => c.ManifestModule.Name);
那么这条消息到底在告诉我什么?在这种情况下,我怎样才能得到我加载的程序集?