* roottypes.cs: Rename from tree.cs.
[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
37 namespace System.IO {
38
39         [Serializable]
40         public class FileLoadException : IOException {
41
42                 // Fields
43                 const int Result = unchecked ((int)0x80070002);
44                 string msg;
45                 Exception inner;
46                 string fileName;
47                 string fusionLog;
48                 
49                 // Constructors
50                 public FileLoadException ()
51                         : base (Locale.GetText ("I/O Error"))
52                 {
53                         HResult = Result;
54                         msg = Locale.GetText ("I/O Error");
55                 }
56
57                 public FileLoadException (string message)
58                         : base (message)
59                 {
60                         HResult = Result;
61                         msg = message;
62                 }
63
64                 public FileLoadException (string message, string fileName)
65                         : base (message)
66                 {
67                         HResult = Result;
68                         this.msg = message;
69                         this.fileName = fileName;
70                 }               
71
72                 public FileLoadException (string message, Exception inner)
73                         : base (message, inner)
74                 {
75                         HResult = Result;
76                         msg = message;
77                         this.inner = inner;
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                         this.inner = inner;
87                 }
88
89                 protected FileLoadException (SerializationInfo info, StreamingContext context)
90                 {
91                         fileName = info.GetString ("FileLoad_FileName");
92                         fusionLog = info.GetString ("FileLoad_FusionLog");
93                 }
94
95                 // Properties
96                 public override string Message {
97                         get { return msg; }
98                 }
99
100                 public string FileName
101                 {
102                         get { return fileName; }
103                 }
104                 
105                 public string FusionLog {
106                         // note: MS runtime throws a SecurityException when the Exception is created
107                         // but a FileLoadException once the exception as been thrown. Mono always
108                         // throw a SecurityException in both case (anyway fusionLog is currently empty)
109                         [SecurityPermission (SecurityAction.Demand, ControlEvidence=true, ControlPolicy=true)]
110                         get { return fusionLog; }
111                 }
112
113                 // Methods
114                 public override void GetObjectData (SerializationInfo info, StreamingContext context)
115                 {
116                         base.GetObjectData (info, context);
117                         info.AddValue ("FileLoad_FileName", fileName);
118                         info.AddValue ("FileLoad_FusionLog", fusionLog);
119                 }
120
121                 public override string ToString ()
122                 {
123                         StringBuilder sb = new StringBuilder (GetType ().FullName);
124                         sb.AppendFormat (": {0}", msg);
125
126                         if (fileName != null)
127                                 sb.AppendFormat (" : {0}", fileName);
128
129                         if (this.InnerException != null)
130                                 sb.AppendFormat (" ----> {0}", InnerException);
131
132                         if (this.StackTrace != null) {
133                                 sb.Append (Environment.NewLine);
134                                 sb.Append (StackTrace);
135                         }
136
137                         return sb.ToString ();
138                 }
139         }
140 }