e978bac6499e1ea535eedb518b00dd738654b80c
[mono.git] / mcs / class / corlib / System.IO / FileLoadException.cs
1 //
2 // System.IO.FileLoadException.cs
3 //
4 // Author:
5 //   Paolo Molaro (lupus@ximian.com)
6 //   Duncan Mak (duncan@ximian.com)
7 //
8 // (C) 2001 Ximian, Inc.  http://www.ximian.com
9 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
10 //
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
18 // 
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
21 // 
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 //
30
31 using System.Globalization;
32 using System.Runtime.Serialization;
33 using System.Security;
34 using System.Security.Permissions;
35 using System.Text;
36 using System.Runtime.InteropServices;
37
38 namespace System.IO {
39
40         [Serializable]
41         [ComVisible (true)]
42         public class FileLoadException : IOException {
43
44                 // Fields
45                 const int Result = unchecked ((int)0x80070002);
46                 string msg;
47                 string fileName;
48                 string fusionLog;
49                 
50                 // Constructors
51                 public FileLoadException ()
52                         : base (Locale.GetText ("I/O Error"))
53                 {
54                         HResult = Result;
55                         msg = Locale.GetText ("I/O Error");
56                 }
57
58                 public FileLoadException (string message)
59                         : base (message)
60                 {
61                         HResult = Result;
62                         msg = message;
63                 }
64
65                 public FileLoadException (string message, string fileName)
66                         : base (message)
67                 {
68                         HResult = Result;
69                         this.msg = message;
70                         this.fileName = fileName;
71                 }               
72
73                 public FileLoadException (string message, Exception inner)
74                         : base (message, inner)
75                 {
76                         HResult = Result;
77                         msg = message;
78                 }
79
80                 public FileLoadException (string message, string fileName, Exception inner)
81                         : base (message, inner)
82                 {
83                         HResult = Result;
84                         this.msg = message;
85                         this.fileName = fileName;
86                 }
87
88                 protected FileLoadException (SerializationInfo info, StreamingContext context)
89                 {
90                         fileName = info.GetString ("FileLoad_FileName");
91                         fusionLog = info.GetString ("FileLoad_FusionLog");
92                 }
93
94                 // Properties
95                 public override string Message {
96                         get { return msg; }
97                 }
98
99                 public string FileName
100                 {
101                         get { return fileName; }
102                 }
103                 
104                 public string FusionLog {
105                         // note: MS runtime throws a SecurityException when the Exception is created
106                         // but a FileLoadException once the exception as been thrown. Mono always
107                         // throw a SecurityException in both case (anyway fusionLog is currently empty)
108                         [SecurityPermission (SecurityAction.Demand, ControlEvidence=true, ControlPolicy=true)]
109                         get { return fusionLog; }
110                 }
111
112                 // Methods
113                 public override void GetObjectData (SerializationInfo info, StreamingContext context)
114                 {
115                         base.GetObjectData (info, context);
116                         info.AddValue ("FileLoad_FileName", fileName);
117                         info.AddValue ("FileLoad_FusionLog", fusionLog);
118                 }
119
120                 public override string ToString ()
121                 {
122                         StringBuilder sb = new StringBuilder (GetType ().FullName);
123                         sb.AppendFormat (": {0}", msg);
124
125                         if (fileName != null)
126                                 sb.AppendFormat (" : {0}", fileName);
127
128                         if (this.InnerException != null)
129                                 sb.AppendFormat (" ----> {0}", InnerException);
130
131                         if (this.StackTrace != null) {
132                                 sb.Append (Environment.NewLine);
133                                 sb.Append (StackTrace);
134                         }
135
136                         return sb.ToString ();
137                 }
138         }
139 }