Is there a simple way to identify Reflection.Emit-generated assemblies? When processing all assemblies loaded into an application domain, Assembly
instances of dynamically generated assemblies don't behave the same as for standard assemblies. For example, accessing the CodeBase
property leads to an exception:
string codeBase;
try
{
codeBase = assembly.CodeBase;
}
catch(NotSupportedException)
{
// assemblies generated via Reflection.Emit throw an exception when CodeBase is accessed
codeBase = null;
}
Is there a better way to recognize this situation and avoid the try … catch
block?