vcRobe
vcRobe

Reputation: 1781

Error unit testing ASP.NET MVC 5

I'm developing an ASP.NET MVC 5 app and it works as expected.

Now trying to unit test one controller in the test project when I run it I get the following exception

An exception of type 'System.IO.FileLoadException' occurred in ControlCompras.UnitTests.dll but was not handled in user code

Additional information: Could not load file or assembly 'System.Web.Mvc, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

However the version of System.Web.Mvc.dll that is referenced in the Test project is 5.2.2.0. It's the same assembly that's referenced by the ASP.NET project.

Why it's trying to load the version 5.0.0.0?

Can someone please give me a clue about how to solve this?

Here's what I've tried:

  1. The System.Web.Mvc.dll has the property Copy Local = true
  2. I've reinstalled the package Microsoft.AspNet.Mvc with the following nuget command install-package Microsoft.AspNet.Mvc -version 5.2.2

here's the app.config file

Thanks in advance.

Upvotes: 0

Views: 464

Answers (2)

Mital Gevariya
Mital Gevariya

Reputation: 11

I had the same error. I tried updating "System.Web.Mvc" package from nuget package manager in the unit test project. But it didn't reflect any change in references to the unit test project. Heres my solution:

  • I opened the main project references and double clicked "System.Web.Mvc" package which led to view in object browser.
  • Then I just copied that path of file opened it in file explorer. where I found dll file of "System.Web.Mvc" package.
  • I did the same procedure for the unit test project where I found dll file of "System.Web.Mvc" package of older version.
  • I replaced it with dll file of "System.Web.Mvc" package found from main project.

    It worked. Though it's not proper way for upgrading pages but its quick.

Upvotes: 1

Alexander
Alexander

Reputation: 1829

I just encountered this error. But I was able to fix it by updating the nuget packages for both the asp.net project and unit test project. Nuget will update both references. The conflict may not occur in System.web.Mvc but in other files as well.

Upvotes: 0

Related Questions