TypeLoadException Constructor (String)

July 28, 2014

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

Namespace:  System
Assembly:  mscorlib (in mscorlib.dll)

public TypeLoadException(
	string message
)

Parameters

message
Type: System.String
The message that describes the error.

The content of the message parameter should be understandable to the user. The caller of this constructor is required to ensure that this string has been localized for the current system culture.

The following table shows the initial property values for an instance of TypeLoadException.

Property

Value

InnerException

A null reference (Nothing in Visual Basic).

Message

The error message string.

The following code example demonstrates the TypeLoadException(String) constructor. It contains a method that generates a TypeLoadException with a custom message, and displays the error message.


using System;

public class Example
{
   public static void Demo(System.Windows.Controls.TextBlock outputBlock)
   {
      outputBlock.Text += "This program throws an exception upon successful run." + "\n";
      outputBlock.Text += "Generating TypeLoadException with custom message..." + "\n";
      try
      {
         // Generate a new instance of TypeLoadException.
         TypeLoadExceptionDemoClass.GenerateException();
      }
      catch (TypeLoadException e)
      {
         outputBlock.Text += "TypeLoadException: \n\tError Message = " + e.Message + "\n";
      }
      catch (Exception e)
      {
         outputBlock.Text += "Exception: \n\tError Message = " + e.Message + "\n";
      }
   }
}

class TypeLoadExceptionDemoClass
{
   public static bool GenerateException()
   {
      // Throw a TypeLoadException with custom defined message.
      throw new TypeLoadException("This is a custom generated TypeLoadException error message");
   }
}


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft