Merge pull request #297 from ermshiperete/4959
[mono.git] / mcs / class / corlib / System / BadImageFormatException.cs
index ed0f6cb4b8ccadfe556df28b8851d14cdc9f144d..f48fb2274c193ee6d1a6cc4b362901e405ff8cce 100644 (file)
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
 
+using System.Globalization;
 using System.Runtime.Serialization;
 using System.Security.Permissions;
+using System.Runtime.InteropServices;
+using System.Text;
 
 namespace System
 {
        [Serializable]
+       [ComVisible (true)]
        public class BadImageFormatException : SystemException
        {
                const int Result = unchecked ((int)0x8007000B);
@@ -45,7 +49,7 @@ namespace System
 
                // Constructors
                public BadImageFormatException ()
-                       : base (Locale.GetText ("Invalid file image."))
+                       : base (Locale.GetText ("Format of the executable (.exe) or library (.dll) is invalid."))
                {
                        HResult = Result;
                }
@@ -63,8 +67,8 @@ namespace System
                        fusionLog = info.GetString ("BadImageFormat_FusionLog");
                }
 
-               public BadImageFormatException (string message, Exception innerException)
-                       : base (message, innerException)
+               public BadImageFormatException (string message, Exception inner)
+                       : base (message, inner)
                {
                        HResult = Result;
                }
@@ -76,8 +80,8 @@ namespace System
                        HResult = Result;
                }
 
-               public BadImageFormatException (string message, string fileName, Exception innerException)
-                       : base (message, innerException)
+               public BadImageFormatException (string message, string fileName, Exception inner)
+                       : base (message, inner)
                {
                        this.fileName = fileName;
                        HResult = Result;
@@ -86,7 +90,15 @@ namespace System
                // Properties
                public override string Message
                {
-                       get { return base.Message; }
+                       get {
+                               if (base.message == null) {
+                                       return string.Format (CultureInfo.CurrentCulture,
+                                               "Could not load file or assembly '{0}' or one of"
+                                               + " its dependencies. An attempt was made to load"
+                                               + " a program with an incorrect format.", fileName);
+                               }
+                               return base.Message;
+                       }
                }
 
                public string FileName
@@ -113,9 +125,23 @@ namespace System
 
                public override string ToString ()
                {
-                       if (fileName != null)
-                               return Locale.GetText ("Filename: ") + fileName;
-                       return base.ToString ();
+                       StringBuilder sb = new StringBuilder (GetType ().FullName);
+                       sb.AppendFormat (": {0}", Message);
+
+                       if (fileName != null && fileName.Length > 0) {
+                               sb.Append (Environment.NewLine);
+                               sb.AppendFormat ("File name: '{0}'", fileName);
+                       }
+
+                       if (this.InnerException != null)
+                               sb.AppendFormat (" ---> {0}", InnerException);
+
+                       if (this.StackTrace != null) {
+                               sb.Append (Environment.NewLine);
+                               sb.Append (StackTrace);
+                       }
+
+                       return sb.ToString ();
                }
        }
 }