This documentation is archived and is not being maintained.

TypeLoadException Constructor

.NET Framework 1.1

Initializes a new instance of the TypeLoadException class.

Overload List

Initializes a new instance of the TypeLoadException class.

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New()
[C#] public TypeLoadException();
[C++] public: TypeLoadException();
[JScript] public function TypeLoadException();

Initializes a new instance of the TypeLoadException class with a specified error message.

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New(String)
[C#] public TypeLoadException(string);
[C++] public: TypeLoadException(String*);
[JScript] public function TypeLoadException(String);

Initializes a new instance of the TypeLoadException class with serialized data.

[Visual Basic] Protected Sub New(SerializationInfo, StreamingContext)
[C#] protected TypeLoadException(SerializationInfo, StreamingContext);
[C++] protected: TypeLoadException(SerializationInfo*, StreamingContext);
[JScript] protected function TypeLoadException(SerializationInfo, StreamingContext);

Initializes a new instance of the TypeLoadException class with a specified error message and a reference to the inner exception that is the cause of this exception.

Supported by the .NET Compact Framework.

[Visual Basic] Public Sub New(String, Exception)
[C#] public TypeLoadException(string, Exception);
[C++] public: TypeLoadException(String*, Exception*);
[JScript] public function TypeLoadException(String, Exception);

Example

[Visual Basic, C#, C++] Note   This example shows how to use one of the overloaded versions of the TypeLoadException constructor. For other examples that might be available, see the individual overload topics.
[Visual Basic] 
Imports System
Imports System.Runtime.InteropServices

Public Class TypeLoadException_Constructor3
   Public Shared Sub Main()
      Console.WriteLine("Calling a method in a non-existent DLL which triggers a TypeLoadException.")
      Try
         TypeLoadExceptionDemoClass.GenerateException()
      Catch e As TypeLoadException
         Console.WriteLine(("TypeLoadException: " + ControlChars.Cr + ControlChars.Tab + "Error Message = " + e.Message))
         Console.WriteLine(("TypeLoadException: " + ControlChars.Cr + ControlChars.Tab + "InnerException Message = " + e.InnerException.Message))
      Catch e As Exception
         Console.WriteLine(("Exception: " + ControlChars.Cr + ControlChars.Tab + "Error Message = " + e.Message))
      End Try
   End Sub 'Main
End Class 'TypeLoadException_Constructor3

Class TypeLoadExceptionDemoClass
   ' A call to this method will raise a TypeLoadException.
   Public Declare Sub NonExistentMethod Lib "NonExistentDLL.DLL" Alias "MethodNotExists" ()

   Public Shared Sub GenerateException()
      Try
         NonExistentMethod()
      Catch e As TypeLoadException
         ' Rethrow exception with the exception as inner exception
         Throw New TypeLoadException("This exception was raised due to a call to an invalid method.", e)
      End Try
   End Sub 'GenerateException
End Class 'TypeLoadExceptionDemoClass

[C#] 

using System;
using System.Runtime.InteropServices;

public class TypeLoadException_Constructor3
{
   public static void Main() 
   {
      Console.WriteLine("Calling a method in a non-existent DLL which triggers a TypeLoadException.");
      try 
      {
         TypeLoadExceptionDemoClass.GenerateException();
      }  
      catch (TypeLoadException e)
      {
         Console.WriteLine ("TypeLoadException: \n\tError Message = " + e.Message);
         Console.WriteLine ("TypeLoadException: \n\tInnerException Message = " + e.InnerException.Message );
      }  
      catch (Exception e)
      {
         Console.WriteLine ("Exception: \n\tError Message = " + e.Message);
      }
   }
}

class TypeLoadExceptionDemoClass
{ 
   // A call to this method will raise a TypeLoadException.
   [DllImport("NonExistentDLL.DLL", EntryPoint="MethodNotExists")]
   public static extern void NonExistentMethod();

   public static void GenerateException() 
   {
      try 
      {
         NonExistentMethod();
      }
      catch (TypeLoadException e) 
      {
         // Rethrow exception with the exception as inner exception
         throw new TypeLoadException("This exception was raised due to a call to an invalid method.", e);
      }
   }
}

[C++] 

#using <mscorlib.dll>

using namespace System;
using namespace System::Runtime::InteropServices;

__gc class TypeLoadExceptionDemoClass { 
public:
   // A call to this method will raise a TypeLoadException.
   [DllImport(S"NonExistentDLL.DLL", EntryPoint=S"MethodNotExists")]
   static void NonExistentMethod();

   static void GenerateException() {
      try {
         NonExistentMethod();
      } catch (TypeLoadException* e) {
         // Rethrow exception with the exception as inner exception
         throw new TypeLoadException(S"This exception was raised due to a call to an invalid method.", e);
      }
   }
};

int main() {
   Console::WriteLine(S"Calling a method in a non-existent DLL which triggers a TypeLoadException.");
   try {
      TypeLoadExceptionDemoClass::GenerateException();
   } catch (TypeLoadException* e) {
      Console::WriteLine (S"TypeLoadException: \n\tError Message = {0}", e->Message);
      Console::WriteLine (S"TypeLoadException: \n\tInnerException Message = {0}", e->InnerException->Message);
   } catch (Exception* e) {
      Console::WriteLine (S"Exception: \n\tError Message = {0}", e->Message);
   }
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

See Also

TypeLoadException Class | TypeLoadException Members | System Namespace

Show: