15

So I have a solution contains two project: Example.Api and Example.Api.Test.

Example.API project is my Web API 2 project that talks to Database.

Example.API.Test project is there to unit test against Example.API.

I'm using moq to mock the context and controllers and more.

One problem is that my Example.API.Test project misses a lot assemblies used by Example.API project.

Test project has reference to the Example.API project but all the system assemblies are missing.

for example, The type 'System.Web.Http.ApiController' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Web.Http ...

I could add individual reference to Example.API.Test project but it seems not the right way.

Any tips available?

Thank you.

CodeSchool JJ
  • 585
  • 5
  • 16
  • 4
    Of course you must install *Microsoft.AspNet.WebApi.Core* in your test project as well. Use nuget https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Core/ – Joseph Jeganathan Oct 01 '14 at 19:43
  • So basically I need to separately install missing assemblies right? seems like wasting space :) – CodeSchool JJ Oct 01 '14 at 19:50
  • Yes easily via Nuget `Install-Package` – Joseph Jeganathan Oct 01 '14 at 19:56
  • it turned out webapicore is installed. What's missing is 'System.Web.Http'. When I manually added the reference now it gives error saying: Assembly 'Example.API, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' uses 'System.Web.Http, Version=5.2.2.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher version than referenced assembly 'System.Web.Http, Version=4.0.0.0, Culture=neutral, – CodeSchool JJ Oct 01 '14 at 20:03
  • and nuget doesn't help me with update this specific assembly. :( – CodeSchool JJ Oct 01 '14 at 20:04
  • You don't have to add System.Web.Http manually. Installing *Microsoft.AspNet.WebApi.Core* must include that for you. – Joseph Jeganathan Oct 01 '14 at 20:14
  • install-Package System.Web.Http -Version 5.2.2.0 fails :) – CodeSchool JJ Oct 01 '14 at 20:15
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/62290/discussion-between-joseph-jeganathan-and-codeschool-jj). – Joseph Jeganathan Oct 01 '14 at 20:16
  • oop look into http://stackoverflow.com/questions/20202188/where-can-i-find-a-nuget-package-for-upgrading-to-system-web-http-v5-0-0-0 – CodeSchool JJ Oct 01 '14 at 20:17

1 Answers1

23

Just Follow other's advice! Do Install-Package Microsoft.AspNet.WebApi.Core evenif nuget says it has it.

:)

Quote as Joseph told me "You can easily install the same version by managing packages (right click on the solution level)"

Thank you!

CodeSchool JJ
  • 585
  • 5
  • 16
  • you can remove your manually added dependencies and install via nuget so visual studio will install you all the required dependencies and configurations. run following command in nuget package manager console Install-Package Microsoft.AspNet.WebApi.Core – Jenish Zinzuvadiya Nov 19 '16 at 12:57
  • 1
    This fixed my issue! – Harold_Finch Jun 07 '20 at 20:25