From acde9f105c3fd58310a1a87398fca7eed2180023 Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 10 Feb 2020 14:03:30 -0800 Subject: [PATCH] No-op if ValidateComplexType is validated without the right context Fixes https://github.com/dotnet/aspnetcore/issues/17316 --- .../Blazor/Validation/src/ValidateComplexTypeAttribute.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/Components/Blazor/Validation/src/ValidateComplexTypeAttribute.cs b/src/Components/Blazor/Validation/src/ValidateComplexTypeAttribute.cs index 4769d84767ad..b236f8d6e18d 100644 --- a/src/Components/Blazor/Validation/src/ValidateComplexTypeAttribute.cs +++ b/src/Components/Blazor/Validation/src/ValidateComplexTypeAttribute.cs @@ -19,11 +19,10 @@ public sealed class ValidateComplexTypeAttribute : ValidationAttribute /// 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; } }