This project has moved. For the latest updates, please go here.


Problem with a Must overload.


I'm having trouble using the following overload:
Must<T, TProperty>(Func<TProperty, bool> predicate)
The presence of the generic T in the method definition prevents concise usage such as:
RuleFor(x => x.Title).Must(s => !string.IsNullOrWhiteSpace(s) || s.Length == 0);
Instead I must type:
RuleFor(x => x.Title).Must((string s) => !string.IsNullOrWhiteSpace(s) || s.Length == 0);
The class being validated (T) is not used anywhere in the predicate and can be removed from the method signature.
Closed Apr 24, 2013 at 10:58 AM by JeremyS


JeremyS wrote Mar 21, 2013 at 1:12 PM

I'm not able to reproduce this problem.

The type inference takes care of this so there is no need to explicitly specify the type. The following compiles just fine using FluentValidation 3.4.6:
public class Demo {
    public string Title { get; set; }
public class DemoValidator : AbstractValidator<Demo> {
    public DemoValidator() {
        RuleFor(x => x.Title).Must(s => !string.IsNullOrWhiteSpace(s) || s.Length == 0);
If you're running the latest version, please put together a small sample that reproduces the problem. Thanks.

KurianOfBorg wrote Mar 22, 2013 at 4:07 AM

The error disappears when I click compile. Until then Intellisense is inferring that I'm trying to use the following overload:
Must<T, TProperty>(Func<T,TProperty, bool> predicate)

JeremyS wrote Mar 22, 2013 at 11:18 AM

Which version of visual studio are you seeing the intellisense issue in? I'm running 2012 Pro and don't see this problem at all. Do you have any other code analysis tools installed that could be causing this?

KurianOfBorg wrote Mar 22, 2013 at 11:54 AM

I'm using VS2012 Premium but I've got a lot of stuff installed. It's not worth looking into. Thanks.

KurianOfBorg wrote Mar 22, 2013 at 11:57 AM

I'm actually have similar problems in other parts of my project in the XAML. When I open the project there are errors but they're gone when I compile.