No-op if ValidateComplexType is validated without the right context (#18935)

Fixes https://github.com/dotnet/aspnetcore/issues/17316
This commit is contained in:
Pranav K 2020-02-13 15:29:27 -08:00 committed by GitHub
parent 074f8faf58
commit fb50111c92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 4 deletions

View File

@ -19,11 +19,10 @@ namespace System.ComponentModel.DataAnnotations
/// <inheritdoc />
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
if (!ObjectGraphDataAnnotationsValidator.TryValidateRecursive(value, validationContext))
{
throw new InvalidOperationException($"{nameof(ValidateComplexTypeAttribute)} can only used with {nameof(ObjectGraphDataAnnotationsValidator)}.");
}
ObjectGraphDataAnnotationsValidator.TryValidateRecursive(value, validationContext);
// Validation of the properties on the complex type are responsible for adding their own messages.
// Therefore, we can always return success from here.
return ValidationResult.Success;
}
}