question-mark
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.

Validating Nullable Root Objects

See original GitHub issue

Hi,

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:closed
  • Created 6 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
JeremySkinnercommented, Apr 4, 2017

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)

0reactions
diegofratacommented, Nov 17, 2017

@JeremySkinner well spotted! I edited the comment.

Read more comments on GitHub >

github_iconTop 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 >

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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found