ValidationException Constructors
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Initializes a new instance of the ValidationException class.
Overloads
| Name | Description |
|---|---|
| ValidationException() |
Initializes a new instance of the ValidationException class using an error message generated by the system. |
| ValidationException(String) |
Initializes a new instance of the ValidationException class using a specified error message. |
| ValidationException(SerializationInfo, StreamingContext) |
Obsolete.
Initializes a new instance of the ValidationException class using serialized data. |
| ValidationException(String, Exception) |
Initializes a new instance of the ValidationException class using a specified error message and an inner exception. |
| ValidationException(ValidationResult, ValidationAttribute, Object) |
Initializes a new instance of the ValidationException class by using a validation result, a validation attribute, and the value of the current exception. |
| ValidationException(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. |
ValidationException()
- Source:
- ValidationException.cs
- Source:
- ValidationException.cs
- Source:
- ValidationException.cs
- Source:
- ValidationException.cs
- Source:
- ValidationException.cs
Initializes a new instance of the ValidationException class using an error message generated by the system.
public:
ValidationException();
public ValidationException();
Public Sub New ()
Remarks
This method is the parameterless constructor for the ValidationException class.
To include the failing validation attribute and invalid value in the exception, use ValidationException(String, ValidationAttribute, Object).
Applies to
ValidationException(String)
- Source:
- ValidationException.cs
- Source:
- ValidationException.cs
- Source:
- ValidationException.cs
- Source:
- ValidationException.cs
- Source:
- ValidationException.cs
Initializes a new instance of the ValidationException class using a specified error message.
public:
ValidationException(System::String ^ message);
public ValidationException(string message);
public ValidationException(string? message);
new System.ComponentModel.DataAnnotations.ValidationException : string -> System.ComponentModel.DataAnnotations.ValidationException
Public Sub New (message As String)
Parameters
- message
- String
A specified message that states the error.
Remarks
To include the failing validation attribute and invalid value in the exception, use the ValidationException(String, ValidationAttribute, Object) overload. That overload preserves the attribute in ValidationAttribute and the value in Value.
Applies to
ValidationException(SerializationInfo, StreamingContext)
- Source:
- ValidationException.cs
- Source:
- ValidationException.cs
- Source:
- ValidationException.cs
- Source:
- ValidationException.cs
- Source:
- ValidationException.cs
Caution
This API supports obsolete formatter-based serialization. It should not be called or extended by application code.
Initializes a new instance of the ValidationException class using serialized data.
protected:
ValidationException(System::Runtime::Serialization::SerializationInfo ^ info, System::Runtime::Serialization::StreamingContext context);
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")]
protected ValidationException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
protected ValidationException(System.Runtime.Serialization.SerializationInfo info, System.Runtime.Serialization.StreamingContext context);
[<System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId="SYSLIB0051", UrlFormat="https://aka.ms/dotnet-warnings/{0}")>]
new System.ComponentModel.DataAnnotations.ValidationException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.ComponentModel.DataAnnotations.ValidationException
new System.ComponentModel.DataAnnotations.ValidationException : System.Runtime.Serialization.SerializationInfo * System.Runtime.Serialization.StreamingContext -> System.ComponentModel.DataAnnotations.ValidationException
Protected Sub New (info As SerializationInfo, context As StreamingContext)
Parameters
- info
- SerializationInfo
The object that holds the serialized data.
- context
- StreamingContext
Context information about the source or destination of the serialized object.
- Attributes
Remarks
This constructor is called during deserialization to reconstitute the exception object that is transmitted over a stream.
Applies to
ValidationException(String, Exception)
- Source:
- ValidationException.cs
- Source:
- ValidationException.cs
- Source:
- ValidationException.cs
- Source:
- ValidationException.cs
- Source:
- ValidationException.cs
Initializes a new instance of the ValidationException class using a specified error message and an inner exception.
public:
ValidationException(System::String ^ message, Exception ^ innerException);
public ValidationException(string message, Exception innerException);
public ValidationException(string? message, Exception? innerException);
new System.ComponentModel.DataAnnotations.ValidationException : string * Exception -> System.ComponentModel.DataAnnotations.ValidationException
Public Sub New (message As String, innerException As Exception)
Parameters
- message
- String
The error message.
- innerException
- Exception
The exception that caused the current exception.
Remarks
Use this overload to preserve an exception that caused the validation failure. To include the failing validation attribute and invalid value instead, use ValidationException(String, ValidationAttribute, Object).
Applies to
ValidationException(ValidationResult, ValidationAttribute, Object)
- Source:
- ValidationException.cs
- Source:
- ValidationException.cs
- Source:
- ValidationException.cs
- Source:
- ValidationException.cs
- Source:
- ValidationException.cs
Initializes a new instance of the ValidationException class by using a validation result, a validation attribute, and the value of the current exception.
public:
ValidationException(System::ComponentModel::DataAnnotations::ValidationResult ^ validationResult, System::ComponentModel::DataAnnotations::ValidationAttribute ^ validatingAttribute, System::Object ^ value);
public ValidationException(System.ComponentModel.DataAnnotations.ValidationResult validationResult, System.ComponentModel.DataAnnotations.ValidationAttribute validatingAttribute, object value);
public ValidationException(System.ComponentModel.DataAnnotations.ValidationResult validationResult, System.ComponentModel.DataAnnotations.ValidationAttribute? validatingAttribute, object? value);
new System.ComponentModel.DataAnnotations.ValidationException : System.ComponentModel.DataAnnotations.ValidationResult * System.ComponentModel.DataAnnotations.ValidationAttribute * obj -> System.ComponentModel.DataAnnotations.ValidationException
Public Sub New (validationResult As ValidationResult, validatingAttribute As ValidationAttribute, value As Object)
Parameters
- validationResult
- ValidationResult
The list of validation results.
- validatingAttribute
- ValidationAttribute
The attribute that caused the current exception.
- value
- Object
The value of the object that caused the attribute to trigger the validation error.
Applies to
ValidationException(String, ValidationAttribute, Object)
- Source:
- ValidationException.cs
- Source:
- ValidationException.cs
- Source:
- ValidationException.cs
- Source:
- ValidationException.cs
- Source:
- ValidationException.cs
Initializes a new instance of the ValidationException class using a specified error message, a validation attribute, and the value of the current exception.
public:
ValidationException(System::String ^ errorMessage, System::ComponentModel::DataAnnotations::ValidationAttribute ^ validatingAttribute, System::Object ^ value);
public ValidationException(string errorMessage, System.ComponentModel.DataAnnotations.ValidationAttribute validatingAttribute, object value);
public ValidationException(string? errorMessage, System.ComponentModel.DataAnnotations.ValidationAttribute? validatingAttribute, object? value);
new System.ComponentModel.DataAnnotations.ValidationException : string * System.ComponentModel.DataAnnotations.ValidationAttribute * obj -> System.ComponentModel.DataAnnotations.ValidationException
Public Sub New (errorMessage As String, validatingAttribute As ValidationAttribute, value As Object)
Parameters
- errorMessage
- String
The message that states the error.
- validatingAttribute
- ValidationAttribute
The attribute that caused the current exception.
- value
- Object
The value of the object that caused the attribute to trigger validation error.
Remarks
For more information, see How to: Customize Data Field Validation in the Data Model.