Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error with NinjectValidatorFactory after updating FluentValidation with Nuget

I have the following line of code in my NinjectModule:

Bind<IValidatorFactory>().To<NinjectValidatorFactory>().InSingletonScope();

This used to work fine, but after doing a bunch of updates with Nuget, I'm getting the following errors:

Error 3 The type 'Ninject.Web.Mvc.FluentValidation.NinjectValidatorFactory' cannot be used as type parameter 'TImplementation' in the generic type or method 'Ninject.Syntax.IBindingToSyntax.To()'. There is no implicit reference conversion from 'Ninject.Web.Mvc.FluentValidation.NinjectValidatorFactory' to 'FluentValidation.IValidatorFactory'. D:\Projects\Current...\Configuration\MainModule.cs 19 13

Error 4 The type 'FluentValidation.ValidatorFactoryBase' is defined in an assembly that is not referenced. You must add a reference to assembly 'FluentValidation, Version=2.0.0.0, Culture=neutral, PublicKeyToken=a82054b837897c66'. D:\Projects\Current...\Configuration\MainModule.cs 19 13

It's true that I don't have a reference to FluentValidation Version=2.0.0.0, but I do have a reference to FluentValidation Version=3.4.0.0.

According to the metadata...

  • IValidatorFactory and ValidatorFactoryBase are defined in Assembly FluentValidation.dll.
  • NinjectValidatorFactory is defined in Assembly Ninject.Web.Mvc.FluentValidation.dll.

In my References folder, I have FluentValidation v3.4.0.0 and Ninject.Web.Mvc.FluentValidation v3.0.0.0.

I don't get why the compiler thinks I need FluentValidation Version=2.0.0.0.

Am I doing something wrong, or is this an issue with the Nuget package?

like image 912
devuxer Avatar asked Aug 18 '12 03:08

devuxer


2 Answers

It looks as if the problem is that FluentValidation used to be a signed assembly but is now an unsigned assembly. Ninject.Web.Mvc.FluentValidation, however, still thinks FluentValidation is signed.

If you look at these two assemblies in ILSpy, you will notice the following:

  • Ninject.Web.Mvc.FluentValidation references FluentValidation with the following attributes: FluentValidation, Version=2.0.0.0, Culture=neutral, PublicKeyToken=a82054b837897c66
  • The latest version of FluentValidation, however, has different attributes: FluentValidation, Version=3.4.0.0, Culture=neutral, PublicKeyToken=null

Note that PublicKeyToken has changed to null (unsigned).

Hopefully, there will be a fix to this soon. Meanwhile, the options are to roll back to the previous FluentValidation or fix the reference via a new fork.

Update

Just posted a bug report to Ninject.Web.Mvc.FluentValidation. Hopefully, this will ensure that the issue is resolved quickly.

Update 2

Just in case anyone missed it, the comment from @dismissile below contains a good solution. I gave it a try and it pretty much works. Here's a slight variation with more detail:

  1. Remove all Nuget packages that contain "FluentValidation".
  2. Use Nuget to install FluentValidation-Signed.
  3. Use Nuget to install FluentValidation.MVC3-Signed (or MVC4-Signed)
  4. Using Package Manager Console, enter the following:

    Install-Package Ninject.Web.Mvc.FluentValidation -IgnoreDependencies

Note: I didn't need to manually add a binding redirect to my Web.config (although the Nuget package added one automatically).

like image 96
devuxer Avatar answered Oct 16 '22 11:10

devuxer


The problem is correctly identified by DanM. Here is the comment from the project coordinator

"Going forward the primary nuget package will no longer be strongly named.

A separate package, FluentValidation-signed can be used if you absoloutely need strong naming, but it is recommended that you use the unsigned version." Jeremy Skinner

like image 2
Umair Ahmed Avatar answered Oct 16 '22 11:10

Umair Ahmed