在通过一系列的组件,如迭代AppDomain.CurrentDomain.GetAssemblies(),动态组件会如果您尝试访问诸如codeBase的物业抛出NotSuportedException。你如何判断一个程序集是动态的,而不会触发和捕捉NotSupportedException异常?
When iterating through a set of assemblies, e.g. AppDomain.CurrentDomain.GetAssemblies(), dynamic assemblies will throw a NotSuportedException if you try to access properties like CodeBase. How can you tell that an assembly is dynamic without triggering and catching the NotSupportedException?
要检查组件是动态的:
if (assembly.ManifestModule is System.Reflection.Emit.ModuleBuilder)
这花了我一段时间才能弄清楚,所以这里的提问和回答。
This took me a while to figure out, so here it is asked and answered.
更新:
在.NET 4.0中,现在有一个特性:
In .NET 4.0, there is now a property:
if (assembly.IsDynamic)
上一篇:如何在ASP.NET Core 3.1中获取服务的实例实例、如何在、ASP、NET
下一篇:从.Net core 3.0迁移到3.1导致缺少System.Data.SqlClient程序集错误错误、程序、core、Net