Skip to content

[Bug] Nested Complex Type Validation Fails #76

Closed
@AmirMahdiNassiri

Description

@AmirMahdiNassiri

Describe 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 👍

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions