Thanks. Appreciate the quick feedback.
When I get a chance I will download the source and do a build. Based on what I saw, the NuGet package install just references the libraries for the project. I take it I need to do that manually once I build the source and copy the libraries?
I will also take a second look at the way I have defined the rule against the object to be more in line with your recommendation.
From: JeremyS [email removed]
Sent: Thursday, November 08, 2012 4:08 AM
To: Patrick Woodall
Subject: Re: NullReferenceException using FluentValidation in MVC3 [FluentValidation:400368]
From: JeremyS
Got it - thanks.
Looking at this, it appears the issue was fixed last month in a patch, however I haven't yet got round to doing a new deployment since then. If you download and build from source, then the error should go away.
As expected, the problem was caused by using RuleFor(t => t). Doing this is not supported (with FluentValidation, rules should be defined against properties, not against the object itself). However, although this isn't supported it shouldn't cause a crash. Someone noticed this issue last month and kindly provided a patch for it.
With the TestIsDefined rule, I'd recommend associating it with one of the properties, eg TestID:
public TestValidator()
{
RuleFor(t => t.TestID).Must(TestIsDefined).WithMessage("User must select existing customer or provide at least a new customer name");
}
privatebool TestIsDefined(TestModel model, int? testId)
{
return (TestID.HasValue || (string.IsNullOrWhiteSpace(model.TestName) &&string.IsNullOrWhiteSpace(model.TestDescription)));
}
However, if you really want to use RuleFor(t=>t) then you'll need to call .OverridePropertyName as part of the rule (as FV won't be able to automatically determine which property to associate the rule with).
Jeremy
This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. Information contained in this email and attachment may be subject to copyright or other intellectual property protection. If you have received this email in error please notify the sender. Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of Signature Technologies.
Signature Technologies, dba Com-Net Software, 3728 Benner Rd, Miamisburg, OH 45342 - www.sigtechinc.com