38

I updated MVC4 to MVC5. When you run the application I got an error that I don't have WebMatrix.Data. I installed it PM> Install-Package WebMatrix.Data. Now when you start getting in the browser:

Could not load file or assembly 'WebMatrix.Data, Version = 3.0.0.0, Culture = neutral, PublicKeyToken = 31bf3856ad364e35' or one of its dependencies. Located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Anyone know how to fix this?

Package Manager Console Log

Attempting to resolve dependency 'Microsoft.AspNet.WebPages.Data (≥ 2.0.20710.0)'.
Installing 'WebMatrix.Data 2.0.30506.0'.
You are downloading WebMatrix.Data from Microsoft, the license agreement to which is available at http://www.microsoft.com/web/webpi/eula/aspnetcomponent_rtw_enu.htm. Check the package for additional dependencies, which may come with their own license agreement(s). Your use of the package and dependencies constitutes your acceptance of their license agreements. If you do not accept the license agreement(s), then delete the relevant components from your device.
Successfully installed 'WebMatrix.Data 2.0.30506.0'.
Adding 'WebMatrix.Data 2.0.30506.0' to xxx.
Successfully added 'WebMatrix.Data 2.0.30506.0' to xxx.`

Piece of code Web.config

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="5.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.3.0.0" newVersion="1.3.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="EntityFramework" publicKeyToken="b77a5c561934e089" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.AspNet.Identity.Core" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages.Razor" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebMatrix.WebData" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebMatrix.Data" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
user3128303
  • 747
  • 1
  • 11
  • 26

6 Answers6

97

Go into: Tools > NuGet Package Manager > Package Manager Console

And run the following command:

PM> Install-Package Microsoft.AspNet.WebPages.Data
Maxime Rouiller
  • 13,614
  • 9
  • 57
  • 107
Vinicius Sin
  • 1,571
  • 11
  • 8
  • 2
    yup that did it for me -- had to change to copy-local for one of the references, but i'm up and running with my seeding :D -- thanks! – Anders Juul Mar 04 '15 at 18:16
  • 1
    I had shared dependent projects relying on the older version. I had to sweep through all the references and update to get it to work... which forced my hand to upgrade a site from MVC4 to 5 on all my sites... Knowing this ahead of time I might have done this differently... – Hunter-Orionnoir Apr 25 '16 at 23:32
  • I installed some random NuGet package and got the same error as the OP. I installed this weird package and it fixed the issue. Why is this even an issue in the first place? Like how does this error come about? – Yusha Jun 22 '18 at 14:30
30

This is what worked for me. Took weeks to figure it out.

Make sure your target framework to what you want it to be (I had 4.6.1).

Go into: Tools > NuGet Package Manager > Package Manager Console and do the following commands.

Uninstall-Package Microsoft.AspNet.WebHelpers
Uninstall-Package Microsoft.AspNet.WebPages.OAuth
Uninstall-Package Microsoft.AspNet.WebPages.WebData
Uninstall-Package Microsoft.AspNet.WebPages.Data

Install-Package Microsoft.AspNet.WebPages.Data
Install-Package Microsoft.AspNet.WebPages.WebData
Install-Package Microsoft.AspNet.WebPages.OAuth
Install-Package Microsoft.AspNet.WebHelpers

Hope this helps anyone that tried the other solutions with no luck.

Blue Eyed Behemoth
  • 3,692
  • 1
  • 17
  • 27
14

This is actually a legacy library. You should instead install Microsoft.AspNet.WebPages.Data if you are upgrading from MVC 4 to 5.

PM> Install-Package Microsoft.AspNet.WebPages.Data
Yodacheese
  • 4,787
  • 5
  • 34
  • 42
6

This works as well

Update-Package Microsoft.AspNet.WebPages.Data
Sergiy Lichenko
  • 3,102
  • 2
  • 11
  • 10
0

from your package manager console I can see that your project has Successfully added 'WebMatrix.Data 2.0.30506.0' to xxx.`

So get your web.config in sync with WebMatrix.Data 2.0.30506.0

Shadab Ahmed
  • 556
  • 9
  • 20
  • Explain your answer? Why the program in the initial question is failing? – Coder Mar 08 '17 at 19:42
  • see this line from the config file it says new version is 3.0.0.0 but installed version is not matching it so they need to be in sync. – Shadab Ahmed Apr 04 '18 at 22:03
0

Installing MVC 4 (not the runtime but the full version) fixed it for me.

twasbrillig
  • 17,084
  • 9
  • 43
  • 67