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.

IsInEnum() does not support custom messages

See original GitHub issue

System Details

  • FluentValidation version: v8.4.0
  • Web Framework version: dotnet core 2.2

Issue Description

If I have an enum and I want to set a custom error message, it always appear the default one.

RuleFor(t=> t.MyEnum).IsInEnum().WithMessage("Failed");

Instead of the error be Failed is always The value 'X' is invalid.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
JeremySkinnercommented, Jun 6, 2019

To clarify it’s not needed only when using automatic validation. You can still use it in asp.net projects when validating manually

1reaction
JeremySkinnercommented, Jun 6, 2019

Because FluentValidation actually pre-dates asp.net mvc (and automatic model binding), and is used widely in many scenarios outside of asp.net’s automatic validation.

It can be used to manually validate objects (eg domain models or commands) and It’s regularly used outside of web projects too (eg in desktop apps).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use my custom FluentValidation error message instead of ...
I have tried RuleFor(x => x.Category.ToString()).IsEnumName(typeof(Category)); but had no success. Do you know how can I use my message error?
Read more >
Built-in Validators — FluentValidation documentation
NotEmpty Validator¶. Ensures that the specified property is not null, an empty string or whitespace (or the default value for value types, e.g.,...
Read more >
Built-In, Nested, Custom Validators with FluentValidation
In this article we are going to learn more about different Validators with FluentValidation, that we can use to protect our app from...
Read more >
Fluent Validation for .NET - RSSing.com
IsInEnum <DayOfWeek>();. Now I need to test the validator- not test my data with the validator, but to test the validator itself. The...
Read more >
Validations for Enum Types
Learn how to build validations for enums using Java custom annotations.
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