From fb50111c9244042c9c5bcc43f02753c933092c2a Mon Sep 17 00:00:00 2001 From: Pranav K <prkrishn@hotmail.com> Date: Thu, 13 Feb 2020 15:29:27 -0800 Subject: [PATCH] No-op if ValidateComplexType is validated without the right context (#18935) 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 4769d84767a..b236f8d6e18 100644 --- a/src/Components/Blazor/Validation/src/ValidateComplexTypeAttribute.cs +++ b/src/Components/Blazor/Validation/src/ValidateComplexTypeAttribute.cs @@ -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; } } -- GitLab