[Serializable] |
The FileNotFoundException exception is thrown when the file fails to load because it cannot be located. If the file is located, but cannot be loaded due to insufficient permissions, a SecurityException is thrown.
FileLoadException uses the HRESULT COR_E_FILELOAD, which has the value 0x80131621. This exception can also be thrown from HRESULT 0x80131018.
ctor #1 | Overloaded:.ctor() Default constructor. This constructor is called by derived class constructors to initialize state in this type.Initializes a new instance of the FileLoadException class, setting the Exception.Message property of the new instance to a system-supplied message that describes the error, such as "Could not load the specified file." This message takes into account the current system culture. |
ctor #2 | Overloaded:.ctor(string message) Initializes a new instance of the FileLoadException class with the specified error message. |
ctor #4 | Overloaded:.ctor(string message, Exception inner) Initializes a new instance of the FileLoadException class with a specified error message and a reference to the inner exception that is the cause of this exception. |
ctor #5 | Overloaded:.ctor(string message, string fileName) Initializes a new instance of the FileLoadException class with a specified error message and the name of the file that could not be loaded. |
ctor #6 | Overloaded:.ctor(string message, string fileName, Exception inner) Initializes a new instance of the FileLoadException class with a specified error message, the name of the file that could not be loaded, and a reference to the inner exception that is the cause of this exception. |
FileName | Read-only Gets the name of the file that causes this exception. |
FusionLog | Read-only Gets the log file that describes why an assembly load failed. |
HelpLink (inherited from System.Exception) |
Read-write See base class member description: System.Exception.HelpLink Gets or sets a link to the help file associated with this exception. |
InnerException (inherited from System.Exception) |
Read-only See base class member description: System.Exception.InnerException Gets the Exception instance that caused the current exception. |
Message | Read-only Overridden: Gets the error message and the name of the file that caused this exception. |
Source (inherited from System.Exception) |
Read-write See base class member description: System.Exception.Source Gets or sets the name of the application or the object that causes the error. |
StackTrace (inherited from System.Exception) |
Read-only See base class member description: System.Exception.StackTrace Gets a string representation of the frames on the call stack at the time the current exception was thrown. |
TargetSite (inherited from System.Exception) |
Read-only See base class member description: System.Exception.TargetSite Gets the method that throws the current exception. |
Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
GetBaseException (inherited from System.Exception) |
See base class member description: System.Exception.GetBaseException When overridden in a derived class, returns the Exception that is the root cause of one or more subsequent exceptions. |
GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
GetObjectData | Overridden: Sets the SerializationInfo with the file name and additional exception information. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
ToString | Overridden: Returns the fully qualified name of the current exception, and possibly the error message, the name of the inner exception, and the stack trace. |
ctor #3 | Overloaded:.ctor(SerializationInfo info, StreamingContext context) Initializes a new instance of the FileLoadException class with serialized data. |
HResult (inherited from System.Exception) |
Read-write See base class member description: System.Exception.HResult Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
public FileLoadException(); |
public FileLoadException( |
message
protected FileLoadException( |
info
context
message
inner
The following table shows the initial property values for an instance of FileLoadException.
Property | Value |
---|---|
Exception.InnerException | The inner exception reference. |
FileLoadException.Message | The error message string. |
message
fileName
FileLoadException.FileName is not required to be a file stored on disk; it can be any part of a system that supports access to streams. For example, depending on the system, this class might be able to access a physical device.
message
fileName
inner
FileLoadException.FileName is not required to be a file stored on disk; it can be any part of a system that supports access to streams. For example, depending on the system, this class might be able to access a physical device.
The following table shows the initial property values for an instance of FileLoadException.
Property | Value |
---|---|
Exception.InnerException | The inner exception reference. |
FileLoadException.Message | The error message string. |
public string FileName {get;}
|
This property is read-only.
public string FusionLog {get;}
|
Exception Type | Condition |
---|---|
SecurityException | The caller does not have the required permission. |
public virtual string HelpLink {get; set;}
|
"file:///C:/Applications/Bazzal/help.html#ErrorNum42"
protected int HResult {get; set;}
|
public Exception InnerException {get;}
|
Use the InnerException property to obtain the set of exceptions that led to the current exception.
You can create a new exception that catches an earlier exception. The code that handles the second exception can make use of the additional information from the earlier exception to handle the error more appropriately.
Suppose that there is a function that reads a file and formats the data from that file. In this example, as the code tries to read the file, an IOException is thrown. The function catches the IOException and throws a FileNotFoundException. The IOException could be saved in the Exception.InnerException property of the FileNotFoundException, enabling the code that catches the FileNotFoundException to examine what causes the initial error.
The Exception.InnerException property, which holds a reference to the inner exception, is set upon initialization of the exception object.
using System; public class MyAppException:ApplicationException { public MyAppException (String message) : base (message) {} public MyAppException (String message, Exception inner) : base(message,inner) {} } public class ExceptExample { public void ThrowInner () { throw new MyAppException("ExceptExample inner exception"); } public void CatchInner() { try { this.ThrowInner(); } catch (Exception e) { throw new MyAppException("Error caused by trying ThrowInner.",e); } } } public class Test { public static void Main() { ExceptExample testInstance = new ExceptExample(); try { testInstance.CatchInner(); } catch(Exception e) { Console.WriteLine ("In Main catch block. Caught: {0}", e.Message); Console.WriteLine ("Inner Exception is {0}",e.InnerException); } } }
This code has the following output:
In Main
catch block. Caught: Error caused by trying ThrowInner. Inner Exception is
MyAppException: ExceptExample inner exception at ExceptExample.ThrowInner() at
ExceptExample.CatchInner()
public override string Message {get;}
|
If no message was supplied to the constructor for the current exception, this property returns a system-supplied error message. If the FileLoadException.FileName property is not a null reference, the message includes the file name, for example, "Unable to load file a FileName." (a FileName represents the value returned by FileLoadException.FileName.) If FileLoadException.FileName is null, this is indicated in the system-supplied message as "(null)". The system-supplied message takes into account the current system culture.
This property is read-only.
public virtual string Source {get; set;}
|
public virtual string StackTrace {get;}
|
StackTrace may not report as many method calls as expected, due to code transformations, such as inlining, that occur during optimization.
By default, the stack trace is captured immediately before an exception object is thrown. Use Environment.StackTrace to get stack trace information when no exception is being thrown.
public MethodBase TargetSite {get;}
|
~FileLoadException(); |
public virtual Exception GetBaseException(); |
For all exceptions in a chain of exceptions, the GetBaseException method must return the same object (the base exception).
Use the GetBaseException method when you want to find the root cause of an exception but do not need information about exceptions that may have occurred between the current exception and the first exception.
public virtual int GetHashCode(); |
public override void GetObjectData( |
info
context
Exception Type | Condition |
---|---|
SecurityException | The caller does not have the required permission. |
public Type GetType(); |
protected object MemberwiseClone(); |
public override string ToString(); |
The string representation returned by this method includes the name of the exception, the value of the FileLoadException.Message the value of the FileLoadException.FileName property, and the result of calling Environment.StackTrace. If any of these members is a null reference, its value is not included in the returned string.