mscorlib(4.0.0.0) API with additions
BadImageFormatException.cs
1 using System.IO;
4 using System.Security;
6 
7 namespace System
8 {
10  [Serializable]
11  [ComVisible(true)]
12  [__DynamicallyInvokable]
14  {
15  private string _fileName;
16 
17  private string _fusionLog;
18 
21  [__DynamicallyInvokable]
22  public override string Message
23  {
24  [__DynamicallyInvokable]
25  get
26  {
27  SetMessageField();
28  return _message;
29  }
30  }
31 
34  [__DynamicallyInvokable]
35  public string FileName
36  {
37  [__DynamicallyInvokable]
38  get
39  {
40  return _fileName;
41  }
42  }
43 
46  public string FusionLog
47  {
48  [SecuritySafeCritical]
49  [SecurityPermission(SecurityAction.Demand, Flags = (SecurityPermissionFlag.ControlEvidence | SecurityPermissionFlag.ControlPolicy))]
50  get
51  {
52  return _fusionLog;
53  }
54  }
55 
57  [__DynamicallyInvokable]
59  : base(Environment.GetResourceString("Arg_BadImageFormatException"))
60  {
61  SetErrorCode(-2147024885);
62  }
63 
66  [__DynamicallyInvokable]
67  public BadImageFormatException(string message)
68  : base(message)
69  {
70  SetErrorCode(-2147024885);
71  }
72 
76  [__DynamicallyInvokable]
77  public BadImageFormatException(string message, Exception inner)
78  : base(message, inner)
79  {
80  SetErrorCode(-2147024885);
81  }
82 
86  [__DynamicallyInvokable]
87  public BadImageFormatException(string message, string fileName)
88  : base(message)
89  {
90  SetErrorCode(-2147024885);
91  _fileName = fileName;
92  }
93 
98  [__DynamicallyInvokable]
99  public BadImageFormatException(string message, string fileName, Exception inner)
100  : base(message, inner)
101  {
102  SetErrorCode(-2147024885);
103  _fileName = fileName;
104  }
105 
106  private void SetMessageField()
107  {
108  if (_message == null)
109  {
110  if (_fileName == null && base.HResult == -2146233088)
111  {
112  _message = Environment.GetResourceString("Arg_BadImageFormatException");
113  }
114  else
115  {
116  _message = FileLoadException.FormatFileLoadExceptionMessage(_fileName, base.HResult);
117  }
118  }
119  }
120 
123  [__DynamicallyInvokable]
124  public override string ToString()
125  {
126  string text = GetType().FullName + ": " + Message;
127  if (_fileName != null && _fileName.Length != 0)
128  {
129  text = text + Environment.NewLine + Environment.GetResourceString("IO.FileName_Name", _fileName);
130  }
131  if (base.InnerException != null)
132  {
133  text = text + " ---> " + base.InnerException.ToString();
134  }
135  if (StackTrace != null)
136  {
137  text = text + Environment.NewLine + StackTrace;
138  }
139  try
140  {
141  if (FusionLog == null)
142  {
143  return text;
144  }
145  if (text == null)
146  {
147  text = " ";
148  }
149  text += Environment.NewLine;
150  text += Environment.NewLine;
151  text += FusionLog;
152  return text;
153  }
154  catch (SecurityException)
155  {
156  return text;
157  }
158  }
159 
164  : base(info, context)
165  {
166  _fileName = info.GetString("BadImageFormat_FileName");
167  try
168  {
169  _fusionLog = info.GetString("BadImageFormat_FusionLog");
170  }
171  catch
172  {
173  _fusionLog = null;
174  }
175  }
176 
177  private BadImageFormatException(string fileName, string fusionLog, int hResult)
178  : base(null)
179  {
180  SetErrorCode(hResult);
181  _fileName = fileName;
182  _fusionLog = fusionLog;
183  SetMessageField();
184  }
185 
190  [SecurityCritical]
191  public override void GetObjectData(SerializationInfo info, StreamingContext context)
192  {
193  base.GetObjectData(info, context);
194  info.AddValue("BadImageFormat_FileName", _fileName, typeof(string));
195  try
196  {
197  info.AddValue("BadImageFormat_FusionLog", FusionLog, typeof(string));
198  }
199  catch (SecurityException)
200  {
201  }
202  }
203  }
204 }
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
Serves as the base class for system exceptions namespace.
BadImageFormatException(string message)
Initializes a new instance of the T:System.BadImageFormatException class with a specified error messa...
Definition: __Canon.cs:3
string FileName
Gets the name of the file that causes this exception.
new Type GetType()
Gets the runtime type of the current instance.
Definition: Exception.cs:753
override string Message
Gets the error message and the name of the file that caused this exception.
Describes the source and destination of a given serialized stream, and provides an additional caller-...
string FusionLog
Gets the log file that describes why an assembly load failed.
override void GetObjectData(SerializationInfo info, StreamingContext context)
Sets the T:System.Runtime.Serialization.SerializationInfo object with the file name,...
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
BadImageFormatException()
Initializes a new instance of the T:System.BadImageFormatException class.
BadImageFormatException(string message, string fileName)
Initializes a new instance of the T:System.BadImageFormatException class with a specified error messa...
BadImageFormatException(string message, string fileName, Exception inner)
Initializes a new instance of the T:System.BadImageFormatException class with a specified error messa...
virtual string StackTrace
Gets a string representation of the immediate frames on the call stack.
Definition: Exception.cs:162
override string ToString()
Returns the fully qualified name of this exception and possibly the error message,...
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
The exception that is thrown when a managed assembly is found but cannot be loaded.
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.
BadImageFormatException(SerializationInfo info, StreamingContext context)
Initializes a new instance of the T:System.BadImageFormatException class with serialized data.
The exception that is thrown when the file image of a dynamic link library (DLL) or an executable pro...
SecurityPermissionFlag
Specifies access flags for the security permission object.
BadImageFormatException(string message, Exception inner)
Initializes a new instance of the T:System.BadImageFormatException class with a specified error messa...
The exception that is thrown when a security error is detected.