Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Bug] Nested Complex Type Validation Fails

See original GitHub issue

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 👍

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

icnocopcommented, Oct 3, 2021


I created PR #91 to resolve this issue.

Thank you.

ghostinsidecommented, May 26, 2023

issue is back in v2.1.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Validation error xsd schema with nested complex types
Ok, So I made a mistake in the DTO. Now it is up and working with this change: [XmlElement(IsNullable = true)] public PersonAddress ......
Read more >
How do I validate a nested complex model in Blazor?
To validate the nested complex model, replace the DataAnnotationsValidator with the ObjectGraphDataAnnotationsValidator, which validates the entire object, ...
Read more >
Nested object validation with when not working properly.
When i'm trying to validate a nested object. within when, it is not validating ... color: Yup.mixed().test( 'testName', 'My error message', ...
Read more >
Deep nested validation broken · Issue #614
Description When trying to validate nested objects using @ValidateNested(), whitelist: true and forbidNonWhitelisted: true, error "property ...
Read more >
Validating nested objects with class-validator in NestJS
I'm using class-validator for request validation in NestJS really often. A few days ago I needed to validate a nested object.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found