0

I am integrating FluentValidation with MVC 5.1.0.0. and trying to use StructureMap but I got an error when I am compiling the code:

Error 5 Assembly 'FluentValidation.Mvc, Version=5.4.0.0, Culture=neutral, PublicKeyToken=null' uses 'System.Web.Mvc, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Mvc, Version=5.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' c:\Users\XXXX\Documents\Visual Studio 2013\Projects\XXXX\packages\FluentValidation.MVC5.5.4.0.0\lib\Net45\FluentValidation.Mvc.dll XXX.Web

How can I resolve this error? I tried to install different versions of StructureMap, and it doesn't work. In my Globals.asax.cs I added this code:

    //Configure structuremap
    ObjectFactory.Configure(cfg => cfg.AddRegistry(new MyRegistry()));
    ControllerBuilder.Current.SetControllerFactory(new StructureMapControllerFactory());

    //Configure FV to use StructureMap
    var factory = new StructureMapValidatorFactory();

    //Tell MVC to use FV for validation
    ModelValidatorProviders.Providers.Add(new FluentValidationModelValidatorProvider(factory));
    DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;

Also I have this classes:

using System.Web.Mvc;
using FluentValidation;
using FluentValidationIoC.Controllers;
using FluentValidationIoC.Models;
using StructureMap.Configuration.DSL;

public class MyRegistry : Registry
{
    public MyRegistry()
    {
        For<PersonRepository>().Use<PersonRepository>();
        For<HomeController>().Use<HomeController>();

        For<IValidator<Person>>()
            .Singleton()
            .Use<PersonValidator>();
    }
}

And

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using StructureMap;

namespace Movie.Web.StructureMap
{
    using System;
    using FluentValidation;
    using StructureMap;

    public class StructureMapValidatorFactory : ValidatorFactoryBase
    {
        public override IValidator CreateInstance(Type validatorType)
        {
            return ObjectFactory.TryGetInstance(validatorType) as IValidator;
        }
    }
}

Can anyone tell me how to resolve this issue?

Zinov
  • 3,817
  • 5
  • 36
  • 70
  • @JeremyS this is based on one example from your blog http://www.jeremyskinner.co.uk/2010/02/22/using-fluentvalidation-with-an-ioc-container/ – Zinov Aug 17 '14 at 20:42
  • I'm having the same problem today with the Ninject version. The problem is the bindings used when the project was built and unless we can suss-out a working assembly redirect, we're stuck until an update comes out. – VeteranCoder Oct 10 '14 at 17:19

0 Answers0