[Bug] Nested Complex Type Validation Fails
See original GitHub issueDescribe the bug
Although FluentValidation
supports nested complex types in the model classes (see here), the FluentValidationValidator
throws an exception when editing the nested complex type:
System.InvalidOperationException: Cannot validate instances of type 'Address'. This validator can only validate instances of type 'Customer'
Originating from:
Blazored.FluentValidation.EditContextFluentValidationExtensions.ValidateField(EditContext editContext, ValidationMessageStore messages, FieldIdentifier fieldIdentifier, IServiceProvider serviceProvider, Boolean disableAssemblyScanning, IValidator validator)
To Reproduce
Please have a look at the minimal source project I created to reproduce the issue. Please download the repo, build, and execute the sample.
Expected behavior
Nested complex types should be editable and the validation rules should work accordingly.
Hosting Model (is this issue happening with a certain hosting model?):
- Blazor WebAssembly (.Net 5)
Additional context
I guess if the EditContext.Model
is passed to the ValidationContext
instead of fieldIdentifier.Model
, validation should execute successfully. Perhaps such a change in editContext.OnFieldChanged
can fix the problem.
Many thanks for the awesome library 👍
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:11 (4 by maintainers)
Top GitHub Comments
Hi.
I created PR #91 to resolve this issue.
Thank you.
issue is back in v2.1.0