The Labs \ Source Viewer \ SSCLI \ System \ TypeInitializationException

  1. // ==++==
  2. //
  3. //
  4. // Copyright (c) 2006 Microsoft Corporation. All rights reserved.
  5. //
  6. // The use and distribution terms for this software are contained in the file
  7. // named license.txt, which can be found in the root of this distribution.
  8. // By using this software in any fashion, you are agreeing to be bound by the
  9. // terms of this license.
  10. //
  11. // You must not remove this notice, or any other, from this software.
  12. //
  13. //
  14. // ==--==
  15. /*=============================================================================
  16. **
  17. ** Class: TypeInitializationException
  18. **
  19. **
  20. ** Purpose: The exception class to wrap exceptions thrown by
  21. **          a type's class initializer (.cctor).  This is sufficiently
  22. **          distinct from a TypeLoadException, which means we couldn't
  23. **          find the type.
  24. **
  25. **
  26. =============================================================================*/
  27. using System;
  28. using System.Runtime.Serialization;
  29. using System.Globalization;
  30. using System.Security.Permissions;
  31. namespace System
  32. {
  33.     [Serializable()]
  34.     [System.Runtime.InteropServices.ComVisible(true)]
  35.     public sealed class TypeInitializationException : SystemException
  36.     {
  37.         private string _typeName;
  38.        
  39.         // This exception is not creatable without specifying the
  40.         // inner exception.
  41.         private TypeInitializationException() : base(Environment.GetResourceString("TypeInitialization_Default"))
  42.         {
  43.             SetErrorCode(__HResults.COR_E_TYPEINITIALIZATION);
  44.         }
  45.        
  46.         // This is called from within the runtime. I believe this is necessary
  47.         // for Interop only, though it's not particularly useful.
  48.         private TypeInitializationException(string message) : base(message)
  49.         {
  50.             SetErrorCode(__HResults.COR_E_TYPEINITIALIZATION);
  51.         }
  52.        
  53.         public TypeInitializationException(string fullTypeName, Exception innerException) : base(String.Format(CultureInfo.CurrentCulture, Environment.GetResourceString("TypeInitialization_Type"), fullTypeName), innerException)
  54.         {
  55.             _typeName = fullTypeName;
  56.             SetErrorCode(__HResults.COR_E_TYPEINITIALIZATION);
  57.         }
  58.        
  59.         internal TypeInitializationException(SerializationInfo info, StreamingContext context) : base(info, context)
  60.         {
  61.             _typeName = info.GetString("TypeName");
  62.         }
  63.        
  64.         public string TypeName {
  65.             get {
  66.                 if (_typeName == null) {
  67.                     return String.Empty;
  68.                 }
  69.                 return _typeName;
  70.             }
  71.         }
  72.        
  73.         [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
  74.         public override void GetObjectData(SerializationInfo info, StreamingContext context)
  75.         {
  76.             base.GetObjectData(info, context);
  77.             info.AddValue("TypeName", TypeName, typeof(string));
  78.         }
  79.        
  80.     }
  81. }

Developer Fusion