Any reason why SimpleInjector.Integration.Web.Mvc is still referencing MVC 3 ?

Sep 10, 2013 at 3:12 AM
Any reason why you are still referencing System.Web.Mvc version 3 in Mvc integration project? Because of this we have to use a binding redirect in MVC 4 project.
Coordinator
Sep 10, 2013 at 9:18 AM
You are probably referencing the System.Web.Mvc NuGet package instead of using the GAC version of System.Web.Mvc.

.NET 4.5 comes with MVC4 preinstalled and with this installation comes the proper binding redirect in the machine config, which prevents you from having to have the binding redirect in your config file.

Instead of blaming Simple Injector, you could also blame the other NuGet packages you are using. Simple Injector just references the System.Web.Mvc from the GAC (which allows .NET to autoamatically pick the newest installed version), while the other packages you installed seem to explicitly reference the System.Web.Mvc NuGet package (instead of referencing the GAC) which causes you to use binding redirects.

So, either you use .NET 4.5 and reference the System.Web.Mvc from the GAC, or you use .NET 4.0 and reference the System.Web.Mvc 4.0 NuGet package and use a binding redirect. Fortunately, NuGet will inject the binding redirects for you.
Sep 10, 2013 at 10:46 AM
Hi Steven,

Thank you for the reply and explanation. I'd have to respectfully disagree with you on your conclusion though:

1) Who references System.Web.Mvc from the GAC in a MVC app? All project templates for File | New | MVC app uses the Nuget MVC package. I can somehow understand why library projects references GAC, but I've never come across a MVC app using GAC for System.Web.Mvc.

2) The biggest snag for me was that the Empty MVC project template makes use of the MVC NuGet package, BUT does not setup any binding redirects. It took me some time to figure out what was happening. All other MVC project templates do setup the binding redirects by default though, it seems it is only the Empty template that does not.

So given (2) above, would you consider adding a note to the MVC integration documentation page that states something like:
"If you are starting from an Empty MVC project template (File | New | Project | MVC 4 | Empty Project Template) you have to manually setup System.Web.Mvc binding redirects, or reference System.Web.Mvc from the GAC"

This might save someone else some wasted time in the future.

PS Thank you again for Simple Injector and your blog posts on Commands and Queries. I've learned much from your blog posts.
Coordinator
Sep 10, 2013 at 10:50 AM
I wasn't aware of this glitch in the Empty MVC project. That's nasty. I will directly add the warning to the documentation.
Marked as answer by dot_NET_Junkie on 3/2/2014 at 10:53 AM
Sep 10, 2013 at 11:02 AM
dot_NET_Junkie wrote:
I wasn't aware of this glitch in the Empty MVC project. That's nasty. I will directly add the warning to the documentation.
Awesome, thank you!
Mar 24 at 8:27 AM
Edited Mar 24 at 8:27 AM
Any reason why you are still referencing System.Web.Mvc version 3 in Mvc integration project? I can not use FxCop to analyze my code because of version conflicting of System.Web.MVC

Here's build output. It indicates that SimpleInjector.Integration.Web.Mvc.dll is built with System.Web.MVC 3.0
  Unified primary reference "System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35".
  Using this version instead of original version "3.0.0.0" in "xx\packages\SimpleInjector.Integration.Web.Mvc.2.5.0\lib\net40\SimpleInjector.Integration.Web.Mvc.dll" because AutoUnify is 'true'.
Coordinator
Mar 24 at 8:59 AM
The integration package refers version 3.0 since it is compatible with MVC 3.0 and up. If we would refer to version 4, the package would become unusable for anyone who is using version 3, while now you can simply add a binding redirect in your config file (what NuGet does for you automatically) and the package works with MVC 4 as well.

Here's an example of such configuration:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.9.0.0" newVersion="4.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>