3 // Copyright (c) Microsoft Corporation. All rights reserved.
6 ////////////////////////////////////////////////////////////////////////////////
7 ////////////////////////////////////////////////////////////////////////////////
9 // ReflectionTypeLoadException is thrown when multiple TypeLoadExceptions may occur.
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.
20 namespace System
.Reflection
{
23 using System
.Runtime
.Serialization
;
24 using System
.Security
.Permissions
;
25 using System
.Diagnostics
.Contracts
;
27 [System
.Runtime
.InteropServices
.ComVisible(true)]
28 public sealed class ReflectionTypeLoadException
: SystemException
, ISerializable
{
29 private Type
[] _classes
;
30 private Exception
[] _exceptions
;
32 // private constructor. This is not called.
33 private ReflectionTypeLoadException()
34 : base(Environment
.GetResourceString("ReflectionTypeLoad_LoadFailed")) {
35 SetErrorCode(__HResults
.COR_E_REFLECTIONTYPELOAD
);
38 // private constructor. This is called from inside the runtime.
39 private ReflectionTypeLoadException(String message
) : base(message
) {
40 SetErrorCode(__HResults
.COR_E_REFLECTIONTYPELOAD
);
43 public ReflectionTypeLoadException(Type
[] classes
, Exception
[] exceptions
) : base(null)
46 _exceptions
= exceptions
;
47 SetErrorCode(__HResults
.COR_E_REFLECTIONTYPELOAD
);
50 public ReflectionTypeLoadException(Type
[] classes
, Exception
[] exceptions
, String message
) : base(message
)
53 _exceptions
= exceptions
;
54 SetErrorCode(__HResults
.COR_E_REFLECTIONTYPELOAD
);
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
[])));
63 get {return _classes;}
66 public Exception
[] LoaderExceptions
{
67 get {return _exceptions;}
70 [System
.Security
.SecurityCritical
] // auto-generated_required
71 public override void GetObjectData(SerializationInfo info
, StreamingContext context
) {
73 throw new ArgumentNullException("info");
75 Contract
.EndContractBlock();
76 base.GetObjectData(info
, context
);
77 info
.AddValue("Types", _classes
, typeof(Type
[]));
78 info
.AddValue("Exceptions", _exceptions
, typeof(Exception
[]));