2017-12-21 2 views
0

문제를 디버깅하는 동안 mscorlib을 조사 중이며 GetName() (System.Reflection.Assembly)입니다.Decompiled 때 System.Reflection.Assembly의 GetName이 NotImplementedException을 throw하는 것으로 나타나는 이유는 무엇입니까?

dotPeek의 메서드에 대한 코드를 보면 또한 reference sourceGetName()의 코드가 그 안에 아무것도 없어 보인다 및 던져 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 기본 클래스이기 때문이다

+1

"Assembly"에서 파생 된 * 유형이 있습니다. 특히 ['RuntimeAssembly'] (http://referencesource.microsoft.com/#mscorlib/system/reflection/assembly.cs,73b5be5e9c2474b2,references). –

답변

3

, 당신은 (이 특정 환경에서) 실행시 다시 얻을 실제 목적은 그 메소드를 구현 않는 RuntimeAssembly이다.

Assembly 개체를 얻는 방법에 따라 실제 런타임 코드 나 반사 전용 등반이나 기타 등등 다른 실제 유형이 있습니다.

그러나 Assembly은 기본 클래스입니다.

나는이 말을 할 수 명백하게 Assembly 클래스는 reference source에서 분명하게 알 수 있듯이, 추상적이기 때문에 :

public abstract class Assembly : _Assembly, IEvidenceFactory, ICustomAttributeProvider, ISerializable 

그리고 그것은 또한 documented이다 : 따라서

[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 

, 그 맞는 객체의 인스턴스 Assembly 변수는 파생 클래스 여야합니다.

+0

어셈블리는'abstract' 클래스이므로 항상 기본 클래스입니다. –

관련 문제