Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

ValidationException Constructor (String, ValidationAttribute, Object)

Initializes a new instance of the ValidationException class using a specified error message, a validation attribute, and the value of the current exception.

Namespace:  System.ComponentModel.DataAnnotations
Assembly:  System.ComponentModel.DataAnnotations (in System.ComponentModel.DataAnnotations.dll)

public ValidationException(
	string errorMessage,
	ValidationAttribute validatingAttribute,
	Object value


Type: System.String

The message that describes the error.

Type: System.ComponentModel.DataAnnotations.ValidationAttribute

The attribute that caused the current exception.

Type: System.Object

The value of the object that caused the attribute to trigger validation error.

This constructor initializes a new instance of the ValidationException class using the specified parameters. For example, if a range attribute requires a range of values from 1 to 10 and a value of 20 is received as input, the new validation exception that is thrown will be constructed. The following code snippet shows the range attribute:


public object number;

The validation exception that is constructed will resemble the following code snippet:

throw new ValidationException("This value has to be between 1 to 10",RangeAttribute, 20);

Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003

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

.NET Framework

Supported in: 3.5 SP1

Community Additions

© 2015 Microsoft