2 // System.BadImageFormatException.cs
5 // Sean MacIsaac (macisaac@ximian.com)
6 // Duncan Mak (duncan@ximian.com)
7 // Andreas Nahr (ClassDevelopment@A-SoftTech.com)
9 // (C) 2001 Ximian, Inc.
10 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
12 // Permission is hereby granted, free of charge, to any person obtaining
13 // a copy of this software and associated documentation files (the
14 // "Software"), to deal in the Software without restriction, including
15 // without limitation the rights to use, copy, modify, merge, publish,
16 // distribute, sublicense, and/or sell copies of the Software, and to
17 // permit persons to whom the Software is furnished to do so, subject to
18 // the following conditions:
20 // The above copyright notice and this permission notice shall be
21 // included in all copies or substantial portions of the Software.
23 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
27 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
28 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
29 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 using System.Globalization;
33 using System.Runtime.Serialization;
34 using System.Security.Permissions;
35 using System.Runtime.InteropServices;
42 public class BadImageFormatException : SystemException
44 const int Result = unchecked ((int)0x8007000B);
47 private string fileName;
48 private string fusionLog;
51 public BadImageFormatException ()
52 : base (Locale.GetText ("Format of the executable (.exe) or library (.dll) is invalid."))
57 public BadImageFormatException (string message)
63 protected BadImageFormatException (SerializationInfo info, StreamingContext context)
64 : base (info, context)
66 fileName = info.GetString ("BadImageFormat_FileName");
67 fusionLog = info.GetString ("BadImageFormat_FusionLog");
70 public BadImageFormatException (string message, Exception inner)
71 : base (message, inner)
76 public BadImageFormatException (string message, string fileName)
79 this.fileName = fileName;
83 public BadImageFormatException (string message, string fileName, Exception inner)
84 : base (message, inner)
86 this.fileName = fileName;
91 public override string Message
94 if (base.message == null) {
95 return string.Format (
96 "Could not load file or assembly '{0}' or one of"
97 + " its dependencies. An attempt was made to load"
98 + " a program with an incorrect format.", fileName);
104 public string FileName
106 get { return fileName; }
109 [MonoTODO ("Probably not entirely correct. fusionLog needs to be set somehow (we are probably missing internal constuctor)")]
110 public string FusionLog {
111 // note: MS runtime throws a SecurityException when the Exception is created
112 // but a FileLoadException once the exception as been thrown. Mono always
113 // throw a SecurityException in both case (anyway fusionLog is currently empty)
114 [SecurityPermission (SecurityAction.Demand, ControlEvidence=true, ControlPolicy=true)]
115 get { return fusionLog; }
119 public override void GetObjectData (SerializationInfo info, StreamingContext context)
121 base.GetObjectData (info, context);
122 info.AddValue ("BadImageFormat_FileName", fileName);
123 info.AddValue ("BadImageFormat_FusionLog", fusionLog);
126 public override string ToString ()
128 StringBuilder sb = new StringBuilder (GetType ().FullName);
129 sb.AppendFormat (": {0}", Message);
131 if (fileName != null && fileName.Length > 0) {
132 sb.Append (Environment.NewLine);
133 sb.AppendFormat ("File name: '{0}'", fileName);
136 if (this.InnerException != null)
137 sb.AppendFormat (" ---> {0}", InnerException);
139 if (this.StackTrace != null) {
140 sb.Append (Environment.NewLine);
141 sb.Append (StackTrace);
144 return sb.ToString ();