C# 为什么System.Reflection.Assembly中的GetName在反编译时会抛出NotImplementedException?

C# 为什么System.Reflection.Assembly中的GetName在反编译时会抛出NotImplementedException?,c#,reflection,mscorlib,C#,Reflection,Mscorlib,在调试一个问题时,我深入到mscorlib,特别是System.Reflection.Assembly中的GetName() 查看dotPeek中方法的代码以及GetName()的代码似乎没有任何内容,并抛出NotImplementedException: #if FEATURE_CORECLR [System.Security.SecurityCritical] // auto-generated #endif public virtual AssemblyName GetNa

在调试一个问题时,我深入到mscorlib,特别是
System.Reflection.Assembly
中的
GetName()

查看dotPeek中方法的代码以及
GetName()
的代码似乎没有任何内容,并抛出
NotImplementedException

#if FEATURE_CORECLR
    [System.Security.SecurityCritical] // auto-generated
#endif
    public virtual AssemblyName GetName()
    {
        return GetName(false);
    }

#if FEATURE_CORECLR
    [System.Security.SecurityCritical] // auto-generated
#endif
    public virtual AssemblyName GetName(bool copiedName)
    {
        throw new NotImplementedException();
    }

有人能解释为什么这看起来会引发异常,但使用一行代码,例如
typeof(object).GetTypeInfo().Assembly.GetName().Version.ToString()
返回DLL的正确版本吗?

这是因为
Assembly
是一个基类,是运行时(在此特定设置中)返回的实际对象是实现该方法的
运行时程序集

根据您获取
程序集
对象的方式,有不同的实际类型在起作用,可以是实际运行时代码,也可以是仅用于反射的探索,等等

但是
Assembly
是一个基类

我可以明确地说这一点,因为
Assembly
类是抽象的,从以下内容可以看出:

这也是:


因此,适合
程序集
变量的对象的任何实例都必须是派生类。

这是因为
程序集
是基类,在运行时(在此特定设置中)返回的实际对象是实现该方法的
运行时程序集

根据您获取
程序集
对象的方式,有不同的实际类型在起作用,可以是实际运行时代码,也可以是仅用于反射的探索,等等

但是
Assembly
是一个基类

我可以明确地说这一点,因为
Assembly
类是抽象的,从以下内容可以看出:

这也是:


所以,,符合
程序集
变量的对象的任何实例都必须是派生类。

请注意,有些类型派生自
程序集
。请注意,有些类型派生自
程序集
。程序集是
抽象
类,因此始终是基类。程序集是
abstract
类,因此始终是基类。
public abstract class Assembly : _Assembly, IEvidenceFactory, ICustomAttributeProvider, ISerializable
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class Assembly : System.Reflection.ICustomAttributeProvider, System.Runtime.InteropServices._Assembly, System.Runtime.Serialization.ISerializable, System.Security.IEvidenceFactory