I have a library module that we use in all of our web applications that lists out all the loaded assemblies (and their version number) into our log4net log file in the Application_Start
method of an ASP.NET webforms application.
This has worked flawlessly for ages - until today, when I tried to use it after an "application warmup" method (described by Scott Guthrie in his blog post had run after deployment to IIS (and before the ASP.NET's Application_Start
ever ran) - now suddenly I'm getting an error:
System.NotSupportedException: The invoked member is not supported in a dynamic assembly.
The code that reports the loaded assemblies looks like this:
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));
}
}
}
}
I'm not 100% clear on which line exactly throws the error - I suspect it's this one:
IEnumerable<Assembly> appAssemblies = AppDomain.CurrentDomain.GetAssemblies().OrderBy(c => c.ManifestModule.Name);
So what exactly is this message telling me? And how can I still get my loaded assemblies in this situation?
I think error is not on
Because accessing
Assembly.Location
property when assembly is dynamically generated will throwNotSupportedException
.That a dynamically generated assembly has not any location then you can't access that property. Yes it may return an empty string but then it would be the same as assemblies created with
Assembly.Load()
...to be serious I can't understand rationale of this choice but that's it.Simply check for it:
Or easier: