Updates referencesource to .NET 4.7
[mono.git] / mcs / class / referencesource / mscorlib / system / reflection / reflectiontypeloadexception.cs
1 // ==++==
2 // 
3 //   Copyright (c) Microsoft Corporation.  All rights reserved.
4 // 
5 // ==--==
6 ////////////////////////////////////////////////////////////////////////////////
7 ////////////////////////////////////////////////////////////////////////////////
8 //
9 // ReflectionTypeLoadException is thrown when multiple TypeLoadExceptions may occur.  
10 // 
11 // <OWNER>Microsoft</OWNER>
12 //  Specifically, when you call Module.GetTypes() this causes multiple class loads to occur.
13 //  If there are failures, we continue to load classes and build an array of the successfully
14 //  loaded classes.  We also build an array of the errors that occur.  Then we throw this exception
15 //  which exposes both the array of classes and the array of TypeLoadExceptions. 
16 //
17 // 
18 // 
19 //
20 namespace System.Reflection {
21     
22     using System;
23     using System.Runtime.Serialization;
24     using System.Security.Permissions;
25     using System.Diagnostics.Contracts;
26     [Serializable]
27 [System.Runtime.InteropServices.ComVisible(true)]
28     public sealed class ReflectionTypeLoadException : SystemException, ISerializable {
29         private Type[] _classes;
30         private Exception[] _exceptions;
31
32         // private constructor.  This is not called.
33         private ReflectionTypeLoadException()
34             : base(Environment.GetResourceString("ReflectionTypeLoad_LoadFailed")) {
35             SetErrorCode(__HResults.COR_E_REFLECTIONTYPELOAD);
36         }
37
38         // private constructor.  This is called from inside the runtime.
39         private ReflectionTypeLoadException(String message) : base(message) {
40             SetErrorCode(__HResults.COR_E_REFLECTIONTYPELOAD);
41         }
42
43         public ReflectionTypeLoadException(Type[] classes, Exception[] exceptions) : base(null)
44         {
45             _classes = classes;
46             _exceptions = exceptions;
47             SetErrorCode(__HResults.COR_E_REFLECTIONTYPELOAD);
48         }
49
50         public ReflectionTypeLoadException(Type[] classes, Exception[] exceptions, String message) : base(message)
51         {
52             _classes = classes;
53             _exceptions = exceptions;
54             SetErrorCode(__HResults.COR_E_REFLECTIONTYPELOAD);
55         }
56
57         internal ReflectionTypeLoadException(SerializationInfo info, StreamingContext context) : base (info, context) {
58             _classes = (Type[])(info.GetValue("Types", typeof(Type[])));
59             _exceptions = (Exception[])(info.GetValue("Exceptions", typeof(Exception[])));
60         }
61     
62         public Type[] Types {
63             get {return _classes;}
64         }
65         
66         public Exception[] LoaderExceptions {
67             get {return _exceptions;}
68         }    
69
70         [System.Security.SecurityCritical]  // auto-generated_required
71         public override void GetObjectData(SerializationInfo info, StreamingContext context) {
72             if (info==null) {
73                 throw new ArgumentNullException("info");
74             }
75             Contract.EndContractBlock();
76             base.GetObjectData(info, context);
77             info.AddValue("Types", _classes, typeof(Type[]));
78             info.AddValue("Exceptions", _exceptions, typeof(Exception[]));
79         }
80
81     }
82 }