1 // Licensed to the .NET Foundation under one or more agreements. 2 // The .NET Foundation licenses this file to you under the MIT license. 3 // See the LICENSE file in the project root for more information. 4 5 /*============================================================================= 6 ** 7 ** 8 ** 9 ** Purpose: The exception class for versioning problems with DLLS. 10 ** 11 ** 12 =============================================================================*/ 13 14 using System.Runtime.Serialization; 15 16 namespace System 17 { 18 [Serializable] 19 [System.Runtime.CompilerServices.TypeForwardedFrom("mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")] 20 public class MissingMemberException : MemberAccessException 21 { MissingMemberException()22 public MissingMemberException() 23 : base(SR.Arg_MissingMemberException) 24 { 25 HResult = HResults.COR_E_MISSINGMEMBER; 26 } 27 MissingMemberException(String message)28 public MissingMemberException(String message) 29 : base(message) 30 { 31 HResult = HResults.COR_E_MISSINGMEMBER; 32 } 33 MissingMemberException(String message, Exception inner)34 public MissingMemberException(String message, Exception inner) 35 : base(message, inner) 36 { 37 HResult = HResults.COR_E_MISSINGMEMBER; 38 } 39 MissingMemberException(string className, string memberName)40 public MissingMemberException(string className, string memberName) 41 { 42 ClassName = className; 43 MemberName = memberName; 44 } 45 MissingMemberException(SerializationInfo info, StreamingContext context)46 protected MissingMemberException(SerializationInfo info, StreamingContext context) 47 : base(info, context) 48 { 49 ClassName = info.GetString("MMClassName"); 50 MemberName = info.GetString("MMMemberName"); 51 Signature = (byte[])info.GetValue("MMSignature", typeof(byte[])); 52 } 53 GetObjectData(SerializationInfo info, StreamingContext context)54 public override void GetObjectData(SerializationInfo info, StreamingContext context) 55 { 56 base.GetObjectData(info, context); 57 info.AddValue("MMClassName", ClassName, typeof(string)); 58 info.AddValue("MMMemberName", MemberName, typeof(string)); 59 info.AddValue("MMSignature", Signature, typeof(byte[])); 60 } 61 62 public override string Message 63 { 64 get 65 { 66 return ClassName == null ? base.Message : SR.Format(SR.MissingMember_Name, ClassName + "." + MemberName + (Signature != null ? " " + FormatSignature(Signature) : string.Empty)); 67 } 68 } 69 FormatSignature(byte[] signature)70 internal static string FormatSignature(byte[] signature) 71 { 72 // This is not the correct implementation, however, it's probably not worth the time to port given that 73 // (1) it's for a diagnostic 74 // (2) Signature is non-null when this exception is created from the native runtime. Which we don't do in .Net Native. 75 // (3) Only other time the signature is non-null is if this exception object is deserialized from a persisted blob from an older runtime. 76 return string.Empty; 77 } 78 79 // If ClassName != null, GetMessage will construct on the fly using it 80 // and the other variables. This allows customization of the 81 // format depending on the language environment. 82 protected string ClassName; 83 protected string MemberName; 84 protected byte[] Signature; 85 } 86 } 87