2

I've searched and found similar questions but the given answers don't work for me.

This is specific to .NET Core. I'm writing unit tests with Xunit and Moq and I'm getting the error of

Exception thrown: 'System.IO.FileNotFoundException'

Additional information: Could not load file or assembly 'System.Net.Http, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

My Test project's project.json file looks like the following:

{
   "version": "1.0.0",
   "buildOptions": {
      "debugType": "portable"
   },
   "dependencies": {
      "xunit": "2.2.0-beta2-build3300",
      "dotnet-test-xunit": "2.2.0-preview2-build1029",
      "My.App.DataAccess": "1.0.0",
      "My.App.Domain": "1.0.0",
      "My.App.Services": "1.0.0",
      "My.App.WebApi": "1.0.0",
      "Microsoft.AspNetCore.TestHost": "1.1.0",
      "Moq": "4.5.30"
   },
   "testRunner": "xunit",

   "frameworks": {
      "net462": {}
   }
}

Only the unit tests are failing. The main application works just fine. I've tried manually forcing System.Net into the project.json but it insists on installing 4.3.0. I'm not sure where it's thinking it needs 4.1.1.0.

EDIT: I noticed that if I copy System.Net.Http.dll from the WebApi project bin to the Test project bin everything works fine. Now, the test project itself does not use anything from the System.Net.Http namespace -- only the method being tested in the WebApi project references it.

Should the Test project have the System.Net.Http.dll copied to it's bin folder as well? If so, why is this not occurring during the build process?

Owen Pauling
  • 11,349
  • 20
  • 53
  • 64
Jake Shakesworth
  • 3,335
  • 4
  • 29
  • 43

1 Answers1

0

This is probably related to this: https://github.com/dotnet/corefx/issues/9846

I recommend updating to VS 2017 and do a binding redirect for the System.Net.Http assembly.

willseward
  • 113
  • 1
  • 1
  • 8
  • How do we do a binding redirect in the new csproj structure? I'm not getting any hits for it on internet searches. – Dagrooms Apr 14 '17 at 19:04