9

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?

Community
  • 1
  • 1
devuxer
  • 41,681
  • 47
  • 180
  • 292

2 Answers2

11

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).

devuxer
  • 41,681
  • 47
  • 180
  • 292
  • thanks dan... it would be great if you can mark it as a bug.. so that it may get a speedy fix. Thanks – Umair Ahmed Aug 19 '12 at 14:39
  • Update: It was already marked as a bug and closed. I am posting the comments from Jeremy Skinner as a separate answer. – Umair Ahmed Aug 19 '12 at 14:46
  • Umair, the problem is not with FluentValidation, it's with Ninject.Web.Mvc.FluentValidation. So, I have still added a bug report to that project (see my update). – devuxer Aug 19 '12 at 16:46
  • @DanM Is there any update on this? I'm not able to roll back to previous versions because the old version of FluentValidation is not compatible with .NET 4.5 – Dismissile Oct 04 '12 at 16:29
  • @Dismissile, check out Umair Ahmed's answer. Are you able to use "FluentValidation-signed" instead? Meanwhile, it wouldn't hurt to leave a comment on the bug report (https://github.com/ninject/ninject.web.mvc.fluentvalidation/issues/3). – devuxer Oct 04 '12 at 21:53
  • 3
    @DanM I was able to solve this doing the following: Installing FluentValidation-Signed and FluentValidation.MVC4-Signed. Installing Ninject.MVC3. Going into package manager console and installed Ninject.Web.Mvc.FluentValidation -IgnoreDependencies. I then created a binding redirect from 3.2 to 3.4.6 so that the Ninject assembly would no longer complain about needing the specific assembly. – Dismissile Oct 05 '12 at 15:19
  • @Dismissile, Sorry for the late reply. Great solution. Thank you. I'll update my answer. – devuxer Dec 29 '12 at 19:52
  • 1
    Mentioning binding redirects was useful. I took a look at the `Ninject.Web.Mvc.FluentValidation` package and there is only 1 class in it, the rest is all NuGet tooling... in this case it seemed that its worth just creating your own `NinjectValidatorFactory` class in your project because it does very little and is unlikely to require much changing. – Pricey Sep 05 '13 at 00:32
2

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

Community
  • 1
  • 1
Umair Ahmed
  • 11,238
  • 5
  • 33
  • 39
  • Thanks for clarifying that FluentValidation really has stopped being strongly named and why. +1. – devuxer Aug 19 '12 at 16:46