This documentation is archived and is not being maintained.

ContractHelper.RaiseContractFailedEvent Method

Used by the binary rewriter to activate the default failure behavior.

Namespace:  System.Diagnostics.Contracts.Internal
Assembly:  mscorlib (in mscorlib.dll)

public static string RaiseContractFailedEvent(
	ContractFailureKind failureKind,
	string userMessage,
	string conditionText,
	Exception innerException


Type: System.Diagnostics.Contracts.ContractFailureKind
The type of failure.
Type: System.String
Additional user information.
Type: System.String
The description of the condition that caused the failure.
Type: System.Exception
The inner exception that caused the current exception.

Return Value

Type: System.String
A null reference (Nothing in Visual Basic) if the event was handled and should not trigger a failure; otherwise, returns the localized failure message.


failureKind is not a valid ContractFailureKind value.

The binary rewriter calls this method to notify listeners about a contract failure. The RaiseContractFailedEvent method does not perform the failure behavior (an assert or throw) itself. If the failure is handled by the listeners, the method returns null. If the failure is not handled by the listeners, a localized failure message is returned.

.NET Framework

Supported in: 4

.NET Framework Client Profile

Supported in: 4

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.