TypeLoadException Constructor (String)

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

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

Syntax

'Declaration
Public Sub New ( _
    message As String _
)
public TypeLoadException(
    string message
)

Parameters

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

Remarks

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.

Examples

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.


Public Class Example
   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)
      outputBlock.Text &= "This program throws an exception upon successful run." & vbCrLf
      outputBlock.Text &= "Generating TypeLoadException with custom message..." & vbCrLf
      Try
         ' Generate a new instance of TypeLoadException.
         TypeLoadExceptionDemoClass.GenerateException()
      Catch e As TypeLoadException
         outputBlock.Text &= ("TypeLoadException: " + ControlChars.Cr + ControlChars.Tab + "Error Message = " + e.Message) & vbCrLf
      Catch e As Exception
         outputBlock.Text &= ("Exception: " + ControlChars.Cr + ControlChars.Tab + "Error Message = " + e.Message) & vbCrLf
      End Try
   End Sub 'Main
End Class 'TypeLoadException_Constructor2

Class TypeLoadExceptionDemoClass
   Public Shared Function GenerateException() As Boolean
      ' Throw a TypeLoadException with custom defined message.
      Throw New TypeLoadException("This is a custom generated TypeLoadException error message")
   End Function 'GenerateException
End Class 'TypeLoadExceptionDemoClass
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");
   }
}

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.