Validating Nullable Root Objects
See original GitHub issueHi,
i have a problem with my validation rules. When my Validator contains only the rule to check if the instance is null, i’m getting a ValidationException as expected.
RuleFor(item => item).NotNull()
If my validator contains other rules beside that, i’m getting in NullReferenceException instead.
RuleFor(item => item).NotNull();
RuleFor(item => item.Prop).NotEmpty();
So why do we have a different behaviour here?
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Validating Nullable Root Objects · Issue #442
Hi, i have a problem with my validation rules. When my Validator contains only the rule to check if the instance is null,...
Read more >FluentValidation rule for null object
I've been trying to work out how to create a FluentValidation rule that checks if the instance of an object it's validating is...
Read more >Handling Nulls in nested objects (Java) - Lalit Vatsal - Medium
where each object and/or value can be nullable. Say our objective is to create a greeting for the name nested three level deep...
Read more >Understanding null safety
Null safety eliminates that problem at the root by changing the type hierarchy. The Null type still exists, but it's no longer a...
Read more >Nullable reference types
This article provides an overview of nullable reference types. You'll learn how the feature provides safety against null reference ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just to clarify, FluentValidation is designed to process rules against properties, and it is a requirement that the root object is not null. In fact, newer versions of FluentValidation throw an explicit exception if you have a null instance (rather than a NullReferenceException)
@JeremySkinner well spotted! I edited the comment.