0

We've MVC-2 application with Fluent Validation (Visual Studio 2010). Recently we migrated it to Visual Studio 2013, MVC 5. After upgrading the Fluent Validation with NuGet, I get the compilation error for following members.

Can't find namespace FluentValidation.Mvc.MetadataExtensions

I'm using UIHint, DataType, DisplayName members from FluentValidation.Mvc.MetadataExtensions.MetadataExtensions class. Which class should I use to fix errors?

EDIT

Broken code

[FluentValidation.Attributes.Validator(typeof(class1Validator))]
public partial class class1: BusinessBase<decimal>
{
}

public class class1Validator: FluentValidation.AbstractValidator<class1>
{
    public class1Validator()
    {
        RuleFor(o => o.FirstName).NotEmpty().Length(1, 60).UIHint("First Name"); //giving error for UIHint
        RuleFor(o => o.Dob).DataType(System.ComponentModel.DataAnnotations.DataType.Date).GreaterThan(DateTime.MinValue).LessThan(DateTime.Now); //giving error for datatype

    }
}

 public class SearchValidator : FluentValidation.AbstractValidator<SearchCriteria>
{
    public SearchValidator()
    {
        RuleFor(o => o.Id).DisplayName("User ID"); //giving error for DisplayName in both lines
        RuleFor(o => o.LastName).DisplayName("Last Name");           

    }


}
5
  • Can you post the broken code? Commented Oct 9, 2015 at 18:46
  • Those are attributes I believe from the .NET libraries. To be sure that FLuentAssertions didn't create their own attributes with the same name, I checked and didn't find a reference. github.com/JeremySkinner/FluentValidation/blob/… Commented Oct 9, 2015 at 18:50
  • @DerekVanCuyk In old app running on MVC 2, it is in the FluentValidation.Mvc.dll, v2.0.50727 assembly. I checked in VS 2010. In VS 2013 I added reference to FluentValidation.Mvc.dll, but didnt help Commented Oct 9, 2015 at 18:56
  • I see them. They're extension methods and they are defined in the file. What version of FLuentValidation.Mvc are you using? Commented Oct 9, 2015 at 19:04
  • The version is 1.3.0.0 Commented Oct 9, 2015 at 19:21

1 Answer 1

1

It appears that these extension methods are deprecated. I created a web project to do some research.

In any recent versions (FluentValidation.Mvc3+), I cannot find the extension methods.

When I created a project with FluentValildation.Mvc2, they exist.

You will need to either use the older library (and I don't know how well they play with the newer versions of MVC) or use the corresponding data annotations for each of the deprecated extension methods.

public class BusinessBase<T>
{
   [UIHint("First Name")]
   public string FirstName { get; set; }
   public DateTime Dob { get; set; }
}

I hope this helps.

Sign up to request clarification or add additional context in comments.

2 Comments

Do you mean to say the in System.data.dataannotation namespace?
System.ComponentModel.DataAnnotations and System.ComponentModel

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.