lundi 2 novembre 2015

FileLoadException Occured for System.Web.Http

I am having a generic problem with probably some unique behavior (and it has pissed me off). I am using .Net framework 4.5 with Visual Studio 2012. I am facing problem running unit tests:

FileLoadException Occured: Could not load file or assembly 'System.Web.Http, Version=5.2.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)

My unit test app.config has following configuration

  <dependentAssembly>
    <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
  </dependentAssembly>

My project (where unit test calling method) has following

  <dependentAssembly>
    <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-5.2.2.0" newVersion="5.2.2.0" />
  </dependentAssembly>

Now the weird problem is, I am able to run the unit tests successfully in my machine (having VS 2013 and VS 2012 installed). However in my colleague's machine (only VS 2012 installed) it fails with above mentioned error. From where I am getting this 5.2.0.0 version number?

The solution (including unit tests) runs fine in Build servers. So I assume my machine config is fine and my colleague's machine has some problem. The project Dll is not present in GAC.

WHAT I TRIED

  1. Deleting the base folder and taking specific in both machine. My machine works fine and other fails.
  2. Enabled all exception settings and caught another error

The assembly with display name 'System.Web.Http' failed to load in the 'Load' binding context of the AppDomain with ID 2. The cause of the failure was: System.IO.FileLoadException: Could not load file or assembly 'System.Web.Http, Version=5.2.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)

  1. Verified my unit test and project bin/debug folder. Both have 5.2.2.0 version of DLL (which is expected). But not sure why my 5.2.0.0 version is being expected for running tests?
  2. Verified that both machine have same IIS features installed (which should be completely irrelevant to my problem).
  3. Made sure all DLL references are referenced through Solution Nuget package manager and hence share same set of DLLs in both machines (if somebody feels it should fix the problem, then I will try to cross verify again).

Remember my machine is able to run the Unit Tests successfully with same configuration. I assume any code change is not required. Could please anyone help me out to resolve this?

Thanks.

Aucun commentaire:

Enregistrer un commentaire