mscorlib(4.0.0.0) API with additions
FileLoadException.cs
5 using System.Security;
7 
8 namespace System.IO
9 {
11  [Serializable]
12  [ComVisible(true)]
13  [__DynamicallyInvokable]
15  {
16  private string _fileName;
17 
18  private string _fusionLog;
19 
22  [__DynamicallyInvokable]
23  public override string Message
24  {
25  [__DynamicallyInvokable]
26  get
27  {
28  SetMessageField();
29  return _message;
30  }
31  }
32 
35  [__DynamicallyInvokable]
36  public string FileName
37  {
38  [__DynamicallyInvokable]
39  get
40  {
41  return _fileName;
42  }
43  }
44 
48  public string FusionLog
49  {
50  [SecuritySafeCritical]
51  [SecurityPermission(SecurityAction.Demand, Flags = (SecurityPermissionFlag.ControlEvidence | SecurityPermissionFlag.ControlPolicy))]
52  get
53  {
54  return _fusionLog;
55  }
56  }
57 
59  [__DynamicallyInvokable]
61  : base(Environment.GetResourceString("IO.FileLoad"))
62  {
63  SetErrorCode(-2146232799);
64  }
65 
68  [__DynamicallyInvokable]
69  public FileLoadException(string message)
70  : base(message)
71  {
72  SetErrorCode(-2146232799);
73  }
74 
78  [__DynamicallyInvokable]
79  public FileLoadException(string message, Exception inner)
80  : base(message, inner)
81  {
82  SetErrorCode(-2146232799);
83  }
84 
88  [__DynamicallyInvokable]
89  public FileLoadException(string message, string fileName)
90  : base(message)
91  {
92  SetErrorCode(-2146232799);
93  _fileName = fileName;
94  }
95 
100  [__DynamicallyInvokable]
101  public FileLoadException(string message, string fileName, Exception inner)
102  : base(message, inner)
103  {
104  SetErrorCode(-2146232799);
105  _fileName = fileName;
106  }
107 
108  private void SetMessageField()
109  {
110  if (_message == null)
111  {
112  _message = FormatFileLoadExceptionMessage(_fileName, base.HResult);
113  }
114  }
115 
118  [__DynamicallyInvokable]
119  public override string ToString()
120  {
121  string text = GetType().FullName + ": " + Message;
122  if (_fileName != null && _fileName.Length != 0)
123  {
124  text = text + Environment.NewLine + Environment.GetResourceString("IO.FileName_Name", _fileName);
125  }
126  if (base.InnerException != null)
127  {
128  text = text + " ---> " + base.InnerException.ToString();
129  }
130  if (StackTrace != null)
131  {
132  text = text + Environment.NewLine + StackTrace;
133  }
134  try
135  {
136  if (FusionLog == null)
137  {
138  return text;
139  }
140  if (text == null)
141  {
142  text = " ";
143  }
144  text += Environment.NewLine;
145  text += Environment.NewLine;
146  text += FusionLog;
147  return text;
148  }
149  catch (SecurityException)
150  {
151  return text;
152  }
153  }
154 
159  : base(info, context)
160  {
161  _fileName = info.GetString("FileLoad_FileName");
162  try
163  {
164  _fusionLog = info.GetString("FileLoad_FusionLog");
165  }
166  catch
167  {
168  _fusionLog = null;
169  }
170  }
171 
172  private FileLoadException(string fileName, string fusionLog, int hResult)
173  : base(null)
174  {
175  SetErrorCode(hResult);
176  _fileName = fileName;
177  _fusionLog = fusionLog;
178  SetMessageField();
179  }
180 
185  [SecurityCritical]
186  public override void GetObjectData(SerializationInfo info, StreamingContext context)
187  {
188  base.GetObjectData(info, context);
189  info.AddValue("FileLoad_FileName", _fileName, typeof(string));
190  try
191  {
192  info.AddValue("FileLoad_FusionLog", FusionLog, typeof(string));
193  }
194  catch (SecurityException)
195  {
196  }
197  }
198 
199  [SecuritySafeCritical]
200  internal static string FormatFileLoadExceptionMessage(string fileName, int hResult)
201  {
202  string s = null;
203  GetFileLoadExceptionMessage(hResult, JitHelpers.GetStringHandleOnStack(ref s));
204  string s2 = null;
205  GetMessageForHR(hResult, JitHelpers.GetStringHandleOnStack(ref s2));
206  return string.Format(CultureInfo.CurrentCulture, s, fileName, s2);
207  }
208 
209  [DllImport("QCall", CharSet = CharSet.Unicode)]
210  [SecurityCritical]
211  [SuppressUnmanagedCodeSecurity]
212  private static extern void GetFileLoadExceptionMessage(int hResult, StringHandleOnStack retString);
213 
214  [DllImport("QCall", CharSet = CharSet.Unicode)]
215  [SecurityCritical]
216  [SuppressUnmanagedCodeSecurity]
217  private static extern void GetMessageForHR(int hresult, StringHandleOnStack retString);
218  }
219 }
static string NewLine
Gets the newline string defined for this environment.
Definition: Environment.cs:449
Describes a set of security permissions applied to code. This class cannot be inherited.
abstract string FullName
Gets the fully qualified name of the type, including its namespace but not its assembly.
Definition: Type.cs:153
Definition: __Canon.cs:3
new Type GetType()
Gets the runtime type of the current instance.
Definition: Exception.cs:753
string FileName
Gets the name of the file that causes this exception.
Describes the source and destination of a given serialized stream, and provides an additional caller-...
FileLoadException(string message)
Initializes a new instance of the T:System.IO.FileLoadException class with the specified error messag...
FileLoadException(SerializationInfo info, StreamingContext context)
Initializes a new instance of the T:System.IO.FileLoadException class with serialized data.
override string ToString()
Returns the fully qualified name of the current exception, and possibly the error message,...
SecurityAction
Specifies the security actions that can be performed using declarative security.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
override string Message
Gets the error message and the name of the file that caused this exception.
string FusionLog
Gets the log file that describes why an assembly load failed.
virtual string StackTrace
Gets a string representation of the immediate frames on the call stack.
Definition: Exception.cs:162
FileLoadException(string message, string fileName, Exception inner)
Initializes a new instance of the T:System.IO.FileLoadException class with a specified error message,...
The exception that is thrown when an I/O error occurs.
Definition: IOException.cs:10
FileLoadException(string message, string fileName)
Initializes a new instance of the T:System.IO.FileLoadException class with a specified error message ...
FileLoadException()
Initializes a new instance of the T:System.IO.FileLoadException class, setting the P:System....
FileLoadException(string message, Exception inner)
Initializes a new instance of the T:System.IO.FileLoadException class with a specified error message ...
CharSet
Dictates which character set marshaled strings should use.
Definition: CharSet.cs:7
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
static CultureInfo CurrentCulture
Gets or sets the T:System.Globalization.CultureInfo object that represents the culture used by the cu...
Definition: CultureInfo.cs:120
The exception that is thrown when a managed assembly is found but cannot be loaded.
override void GetObjectData(SerializationInfo info, StreamingContext context)
Sets the T:System.Runtime.Serialization.SerializationInfo with the file name and additional exception...
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
Definition: Exception.cs:22
Specifies that the class can be serialized.
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
SecurityPermissionFlag
Specifies access flags for the security permission object.
The exception that is thrown when a security error is detected.