126

am i the only one who installed a Windows Update (8.1) on october 15, and suddenly MVC stop working because of this warning?

Warning 1 Could not resolve this reference. Could not locate the assembly "System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

It seems that this windows update installs a newer version of MVC with version number 4.0.0.1, and removes old version from program files folder.

Someone know how to fix this without crawling for each project?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Yogurtu
  • 2,656
  • 3
  • 23
  • 23
  • Where is the reference from? The GAC? Reference assemblies or nuget? – blowdart Oct 16 '14 at 14:28
  • 1
    Read [Microsoft's blog](http://blogs.msdn.com/b/webdev/archive/2014/10/16/microsoft-asp-net-mvc-security-update-broke-my-build.aspx) on the matter. (Thanks to [e4rthdog](http://stackoverflow.com/a/26418330/573634) for linking to this, just commenting to get more visibility) – Hanna Oct 18 '14 at 03:41
  • Related: [`System.Web.MVC` not copied to `bin` folder since MS14-059](http://stackoverflow.com/q/26467078/25124) – Danny Tuppeny Oct 20 '14 at 14:06
  • possible duplicate of [ASP.NET MVC security patch to version 3.0.0.1 breaks build](http://stackoverflow.com/questions/26406877/asp-net-mvc-security-patch-to-version-3-0-0-1-breaks-build) – KyleMit Oct 21 '14 at 21:18
  • 1
    Keep in mind that you'll have to edit the web.config in your production environments too. – Captain Kenpachi Oct 22 '14 at 10:28
  • Will running windows update on the production servers break existing installation too or is it only build time? Also, is there any way to be able to build existing verisons of a project without having to update the code for every old tag? Have put more details as it's own question here: http://stackoverflow.com/questions/26506415/how-to-handle-changeover-from-asp-mvc-version-4-0-0-0-to-4-0-0-1 – Adam Oct 23 '14 at 16:35

9 Answers9

107

The best solution is update DLL to version 4.0.0.1. Try use nuget:

Install-Package Microsoft.AspNet.Mvc -Version 4.0.40804 -Project <your project name>

This will automatically update

  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
    <bindingRedirect oldVersion="0.0.0.0-4.0.0.1" newVersion="4.0.0.1" />
  </dependentAssembly>

You just have to edit version System.Web.Mvc manually in:

<compilation debug="true" targetFramework="4.0">
  <assemblies>
    <add assembly="System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />

Krzysztof Kalinowski
  • 1,451
  • 1
  • 11
  • 5
  • 1
    Yeap, just replace GAC reference with NuGet reference. Worked for us. – abatishchev Oct 16 '14 at 21:18
  • 7
    Read [Microsoft's blog](http://blogs.msdn.com/b/webdev/archive/2014/10/16/microsoft-asp-net-mvc-security-update-broke-my-build.aspx) on the matter. (Thanks to [e4rthdog](http://stackoverflow.com/a/26418330/573634) for linking to this, just commenting to get more visibility) – Hanna Oct 18 '14 at 03:40
  • 10
    Any idea why, after doing the above, I get a whole bunch of these warnings: "ASPNETCOMPILER : warning CS1702: Assuming assembly reference 'System.Web.Mvc, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' matches 'System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35', you may need to supply runtime policy"? – Farinha Oct 24 '14 at 12:57
  • 1
    @Farinha, i have the same warnings. I cant get them away. These warnings kill the build performance. Did you find a way to fix this? – StefanHa Oct 30 '14 at 14:00
  • 3
    No @StefanHa, haven't found a fix yet. I noticed there's a bunch of references to 4.0.0.0 throughout the application, in the Web.config files inside the Views folders, but even after manually changing all of those the warning remains. – Farinha Nov 03 '14 at 08:52
  • 1
    Thanks for this. I spend over three days trying to fix this arrrrggg. +1 – Rob Angelier Nov 24 '14 at 19:28
  • Ah-hah, manually editing that one node, in the Web.config file that's in my Views folder (the main one seemed to be automatically updated, by NuGet I guess) finally ironed out the last of the errors for me in my MVC4 project. – East of Nowhere Jan 24 '15 at 00:28
  • Where is that last `` is an invalid child of ``. – LoJo Sep 27 '15 at 05:03
  • Running the above command only seems to work in VS15, not in VS13. VS13 cannot find the package. – harvzor Jun 10 '16 at 13:09
26

We had to manually touch each .csproj to update the version from 4.0.0.0 to 4.0.0.1 to get our builds going. Quite a pain.

New references should look like:

<Reference Include="System.Web.Mvc, Version=4.0.0.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
Sujith Thankachan
  • 3,508
  • 2
  • 20
  • 25
Zach La Lond
  • 461
  • 4
  • 4
  • 3
    Note the same change is needed for MVC 3.0, the reference should be "3.0.0.1" to get that working again. – Andy Oct 16 '14 at 22:39
  • In my case this was required, and also needed to indicate that "Specific Version" is "True" – pim Mar 09 '16 at 21:56
24

Had the same issue after update:

Security Update for Microsoft ASP.NET MVC 4.0 (KB2993928)
http://support.microsoft.com/kb/2993928

But only for project with a reference to the System.Web.Mvc, not installed by package.

My colleague, who hadn't installed Microsoft ASP.NET MVC 4.0 Runtime and didn't received the update, had no trouble and had still the reference to 4.0.0.0, not to 4.0.0.1

I manually changed the reference to 4.0.0.1, after check-in, my colleague could still build with a reference to 4.0.0.0.
(Working both on Win7 Pro SP1, VS2013 Pro Update 3)

Jaws
  • 296
  • 1
  • 7
22

Please see this blog, the recommended way is to update corresponding NuGet package:

http://blogs.msdn.com/b/webdev/archive/2014/10/16/microsoft-asp-net-mvc-security-update-broke-my-build.aspx

To quote:

The problem can be resolved by implemented one of the following solutions:

  1. (Preferred) Install Microsoft.AspNet.Mvc from the NuGet gallery (this will install a binding redirect in your web.config). You can do this from the NuGet package manager or the NuGet console inside Visual Studio:

    Install-Package Microsoft.AspNet.Mvc -Version -Project PROJECTNAME

    MVC 4 version: 4.0.40804.0

    MVC 3 version: 3.0.50813.1

  2. Manually update the reference to System.Web.MVC.dll (don’t use the one in the GAC).

    Try the Add Reference -> Assemblies -> Extensions dialog box.

Kev
  • 118,037
  • 53
  • 300
  • 385
9

See this: Microsoft Asp.Net MVC Security Update MS14-059 broke my build! MS blogged about it since it obviously brought a lot of confusion

e4rthdog
  • 5,103
  • 4
  • 40
  • 89
4

For web project, you may have to update the configuration in the web.config as well:

  <dependentAssembly>
    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
    <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.0.1"/>
  </dependentAssembly>
Cᴏʀʏ
  • 105,112
  • 20
  • 162
  • 194
THN
  • 41
  • 2
2

You need to change all the references to System.Web.Mvc within your solution. Just delete them and add the new 4.0.0.1 version.

Also in the properties change copy local to true.

And in the web.config add the assambly binding to point to the new version of mvc:

    <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-4.0.0.1" newVersion="4.0.0.1" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>
Robert Benyi
  • 1,623
  • 1
  • 14
  • 10
  • Setting `CopyLocal=true` did not help us; see: [`System.Web.MVC` not copied to `bin` folder since MS14-059](http://stackoverflow.com/q/26467078/25124) – Danny Tuppeny Oct 20 '14 at 14:11
1

Okay,

For me it was two simple steps:

First I changed all references to System.Web.Mvc from 4.0.0.0 to 4.0.0.1,

Then I had to go to the properties of System.Web.Mvc (possibly because I had removed and re-added it) and change copy local to true.

Hope this is helpful for somebody.

edencorbin
  • 2,569
  • 5
  • 29
  • 44
0

If you are still getting the same error after trying @Krzysztof solution or any of the other answers above, one work around that might work for you is to uninstall MVC Runtime 4.0

Ricardo Sanchez
  • 6,079
  • 3
  • 24
  • 31