2 // System.IO.FileNotFoundException.cs
5 // Paolo Molaro (lupus@ximian.com)
6 // Duncan Mak (duncan@ximian.com)
8 // (C) 2001 Ximian, Inc. http://www.ximian.com
9 // Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
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:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
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.
31 using System.Globalization;
32 using System.Runtime.Serialization;
33 using System.Security.Permissions;
39 public class FileNotFoundException : IOException {
41 const int Result = unchecked ((int)0x80131621);
43 private string fileName;
44 private string fusionLog;
47 public FileNotFoundException ()
48 : base (Locale.GetText ("File not found"))
53 public FileNotFoundException (string message)
59 public FileNotFoundException (string message, Exception inner)
60 : base (message, inner)
65 public FileNotFoundException (string message, string fileName)
69 this.fileName = fileName;
72 public FileNotFoundException (string message, string fileName, Exception innerException)
73 : base (message, innerException)
76 this.fileName = fileName;
79 protected FileNotFoundException (SerializationInfo info, StreamingContext context)
80 : base (info, context)
82 fileName = info.GetString ("FileNotFound_FileName");
83 fusionLog = info.GetString ("FileNotFound_FusionLog");
86 public string FileName
88 get { return fileName; }
91 public string FusionLog {
92 // note: MS runtime throws a SecurityException when the Exception is created
93 // but a FileLoadException once the exception as been thrown. Mono always
94 // throw a SecurityException in both case (anyway fusionLog is currently empty)
95 [SecurityPermission (SecurityAction.Demand, ControlEvidence=true, ControlPolicy=true)]
96 get { return fusionLog; }
99 public override string Message {
101 if (base.Message == null)
102 return "File not found";
107 public override void GetObjectData (SerializationInfo info, StreamingContext context)
109 base.GetObjectData (info, context);
110 info.AddValue ("FileNotFound_FileName", fileName);
111 info.AddValue ("FileNotFound_FusionLog", fusionLog);
114 public override string ToString ()
116 StringBuilder sb = new StringBuilder (GetType ().FullName);
117 sb.AppendFormat (": {0}", Message);
119 if (fileName != null)
120 sb.AppendFormat (" : {0}", fileName);
122 if (this.InnerException != null)
123 sb.AppendFormat (" ----> {0}", InnerException);
125 if (this.StackTrace != null) {
126 sb.Append (Environment.NewLine);
127 sb.Append (StackTrace);
130 return sb.ToString ();