mscorlib(4.0.0.0) API with additions
FileNotFoundException.cs
3 using System.Security;
5 
6 namespace System.IO
7 {
10  [ComVisible(true)]
11  [__DynamicallyInvokable]
13  {
14  private string _fileName;
15 
16  private string _fusionLog;
17 
20  [__DynamicallyInvokable]
21  public override string Message
22  {
23  [__DynamicallyInvokable]
24  get
25  {
26  SetMessageField();
27  return _message;
28  }
29  }
30 
33  [__DynamicallyInvokable]
34  public string FileName
35  {
36  [__DynamicallyInvokable]
37  get
38  {
39  return _fileName;
40  }
41  }
42 
46  public string FusionLog
47  {
48  [SecuritySafeCritical]
49  [SecurityPermission(SecurityAction.Demand, Flags = (SecurityPermissionFlag.ControlEvidence | SecurityPermissionFlag.ControlPolicy))]
50  get
51  {
52  return _fusionLog;
53  }
54  }
55 
57  [__DynamicallyInvokable]
59  : base(Environment.GetResourceString("IO.FileNotFound"))
60  {
61  SetErrorCode(-2147024894);
62  }
63 
66  [__DynamicallyInvokable]
67  public FileNotFoundException(string message)
68  : base(message)
69  {
70  SetErrorCode(-2147024894);
71  }
72 
76  [__DynamicallyInvokable]
77  public FileNotFoundException(string message, Exception innerException)
78  : base(message, innerException)
79  {
80  SetErrorCode(-2147024894);
81  }
82 
86  [__DynamicallyInvokable]
87  public FileNotFoundException(string message, string fileName)
88  : base(message)
89  {
90  SetErrorCode(-2147024894);
91  _fileName = fileName;
92  }
93 
98  [__DynamicallyInvokable]
99  public FileNotFoundException(string message, string fileName, Exception innerException)
100  : base(message, innerException)
101  {
102  SetErrorCode(-2147024894);
103  _fileName = fileName;
104  }
105 
106  private void SetMessageField()
107  {
108  if (_message == null)
109  {
110  if (_fileName == null && base.HResult == -2146233088)
111  {
112  _message = Environment.GetResourceString("IO.FileNotFound");
113  }
114  else if (_fileName != null)
115  {
116  _message = FileLoadException.FormatFileLoadExceptionMessage(_fileName, base.HResult);
117  }
118  }
119  }
120 
123  [__DynamicallyInvokable]
124  public override string ToString()
125  {
126  string text = GetType().FullName + ": " + Message;
127  if (_fileName != null && _fileName.Length != 0)
128  {
129  text = text + Environment.NewLine + Environment.GetResourceString("IO.FileName_Name", _fileName);
130  }
131  if (base.InnerException != null)
132  {
133  text = text + " ---> " + base.InnerException.ToString();
134  }
135  if (StackTrace != null)
136  {
137  text = text + Environment.NewLine + StackTrace;
138  }
139  try
140  {
141  if (FusionLog == null)
142  {
143  return text;
144  }
145  if (text == null)
146  {
147  text = " ";
148  }
149  text += Environment.NewLine;
150  text += Environment.NewLine;
151  text += FusionLog;
152  return text;
153  }
154  catch (SecurityException)
155  {
156  return text;
157  }
158  }
159 
164  : base(info, context)
165  {
166  _fileName = info.GetString("FileNotFound_FileName");
167  try
168  {
169  _fusionLog = info.GetString("FileNotFound_FusionLog");
170  }
171  catch
172  {
173  _fusionLog = null;
174  }
175  }
176 
177  private FileNotFoundException(string fileName, string fusionLog, int hResult)
178  : base(null)
179  {
180  SetErrorCode(hResult);
181  _fileName = fileName;
182  _fusionLog = fusionLog;
183  SetMessageField();
184  }
185 
189  [SecurityCritical]
190  public override void GetObjectData(SerializationInfo info, StreamingContext context)
191  {
192  base.GetObjectData(info, context);
193  info.AddValue("FileNotFound_FileName", _fileName, typeof(string));
194  try
195  {
196  info.AddValue("FileNotFound_FusionLog", FusionLog, typeof(string));
197  }
198  catch (SecurityException)
199  {
200  }
201  }
202  }
203 }
static string NewLine
Gets the newline string defined for this environment.
Definition: Environment.cs:449
Describes a set of security permissions applied to code. This class cannot be inherited.
FileNotFoundException(string message, string fileName, Exception innerException)
Initializes a new instance of the T:System.IO.FileNotFoundException class with a specified error mess...
abstract string FullName
Gets the fully qualified name of the type, including its namespace but not its assembly.
Definition: Type.cs:153
Definition: __Canon.cs:3
new Type GetType()
Gets the runtime type of the current instance.
Definition: Exception.cs:753
FileNotFoundException(string message, Exception innerException)
Initializes a new instance of the T:System.IO.FileNotFoundException class with a specified error mess...
FileNotFoundException(SerializationInfo info, StreamingContext context)
Initializes a new instance of the T:System.IO.FileNotFoundException class with the specified serializ...
Describes the source and destination of a given serialized stream, and provides an additional caller-...
override void GetObjectData(SerializationInfo info, StreamingContext context)
Sets the T:System.Runtime.Serialization.SerializationInfo object with the file name and additional ex...
string FileName
Gets the name of the file that cannot be found.
SecurityAction
Specifies the security actions that can be performed using declarative security.
Provides information about, and means to manipulate, the current environment and platform....
Definition: Environment.cs:21
FileNotFoundException()
Initializes a new instance of the T:System.IO.FileNotFoundException class with its message string set...
string FusionLog
Gets the log file that describes why loading of an assembly failed.
virtual string StackTrace
Gets a string representation of the immediate frames on the call stack.
Definition: Exception.cs:162
The exception that is thrown when an I/O error occurs.
Definition: IOException.cs:10
override string Message
Gets the error message that explains the reason for the exception.
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
FileNotFoundException(string message, string fileName)
Initializes a new instance of the T:System.IO.FileNotFoundException class with its message string set...
The exception that is thrown when an attempt to access a file that does not exist on disk fails.
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
Definition: Exception.cs:22
Specifies that the class can be serialized.
override string ToString()
Returns the fully qualified name of this exception and possibly the error message,...
SecurityPermissionFlag
Specifies access flags for the security permission object.
The exception that is thrown when a security error is detected.
FileNotFoundException(string message)
Initializes a new instance of the T:System.IO.FileNotFoundException class with its message string set...