The Labs \ Source Viewer \ SSCLI \ System.Reflection \ ReflectionTypeLoadException

  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. //
  18. // ReflectionTypeLoadException is thrown when multiple TypeLoadExceptions may occur.
  19. // Specifically, when you call Module.GetTypes() this causes multiple class loads to occur.
  20. // If there are failures, we continue to load classes and build an array of the successfully
  21. // loaded classes. We also build an array of the errors that occur. Then we throw this exception
  22. // which exposes both the array of classes and the array of TypeLoadExceptions.
  23. //
  24. //
  25. //
  26. //
  27. namespace System.Reflection
  28. {
  29.    
  30.     using System;
  31.     using System.Runtime.Serialization;
  32.     using System.Security.Permissions;
  33.     [Serializable()]
  34.     [System.Runtime.InteropServices.ComVisible(true)]
  35.     public sealed class ReflectionTypeLoadException : SystemException, ISerializable
  36.     {
  37.         private Type[] _classes;
  38.         private Exception[] _exceptions;
  39.        
  40.         // private constructor. This is not called.
  41.         private ReflectionTypeLoadException() : base(Environment.GetResourceString("ReflectionTypeLoad_LoadFailed"))
  42.         {
  43.             SetErrorCode(__HResults.COR_E_REFLECTIONTYPELOAD);
  44.         }
  45.        
  46.         // private constructor. This is called from inside the runtime.
  47.         private ReflectionTypeLoadException(string message) : base(message)
  48.         {
  49.             SetErrorCode(__HResults.COR_E_REFLECTIONTYPELOAD);
  50.         }
  51.        
  52.         public ReflectionTypeLoadException(Type[] classes, Exception[] exceptions) : base(null)
  53.         {
  54.             _classes = classes;
  55.             _exceptions = exceptions;
  56.             SetErrorCode(__HResults.COR_E_REFLECTIONTYPELOAD);
  57.         }
  58.        
  59.         public ReflectionTypeLoadException(Type[] classes, Exception[] exceptions, string message) : base(message)
  60.         {
  61.             _classes = classes;
  62.             _exceptions = exceptions;
  63.             SetErrorCode(__HResults.COR_E_REFLECTIONTYPELOAD);
  64.         }
  65.        
  66.         internal ReflectionTypeLoadException(SerializationInfo info, StreamingContext context) : base(info, context)
  67.         {
  68.             _classes = (Type[])(info.GetValue("Types", typeof(Type[])));
  69.             _exceptions = (Exception[])(info.GetValue("Exceptions", typeof(Exception[])));
  70.         }
  71.        
  72.         public Type[] Types {
  73.             get { return _classes; }
  74.         }
  75.        
  76.         public Exception[] LoaderExceptions {
  77.             get { return _exceptions; }
  78.         }
  79.        
  80.         [SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags = SecurityPermissionFlag.SerializationFormatter)]
  81.         public override void GetObjectData(SerializationInfo info, StreamingContext context)
  82.         {
  83.             if (info == null) {
  84.                 throw new ArgumentNullException("info");
  85.             }
  86.             base.GetObjectData(info, context);
  87.             info.AddValue("Types", _classes, typeof(Type[]));
  88.             info.AddValue("Exceptions", _exceptions, typeof(Exception[]));
  89.         }
  90.        
  91.     }
  92. }

Developer Fusion