My little WebApi headache that had a very simple solution

Every so often I believe I am amazing. That feeling is very often followed by 3 or 4 hours of banging my head against the wall trying to find a solution to what will turn out to be a very simple problem.
The solution, more often than not, turns out to be something very, very simple. It was WebApi's turn to humble me.

At my company we use NuGet packages for our shared code across systems. We utilise .NET WebApi for data delivery to the UI. Last week I had just done some refactoring that involved moving a controller to another library in the shared code. I tested it locally and everything still worked and I was thinking this was going to be a quick change.
I updated the package in the first of two projects and it worked beautifully. I moved to the second project and the sounds of angels singing were replaced with thunder and lightening as I read:

Error "No type was found that matches the controller named 'xxxxx'."

I checked the Object Browser in Visual Studio to see if the NuGet had actually been updated correctly. I checked to make sure it was referencing the right version. I switched it back to the local reference. I restarted my machine. I cleaned and rebuilt my solution. Everything was correct and it just wasn't working I was stumped as to why it was working in one project and not the other.

I then looked at the set up of WebApi in both projects and they both were identical.
I was about to throw in the towel after 3 hours and revert changes when I had an thought.
WebApi does a look up for all classes that inherit ApiController in all dlls in the bin folder.
I jumped over to the bin folder and saw the issue straight away. The library I had moved my class to was not there. It was referenced in the project but was not being copied to the solution. All I had to do was change the "Copy to local" flag to true and the dll was copied over and the angels returned.
This was not picked up before because all this library contained was client side files such as JS and CSS. It contained server side files that were not being used by this project.
Like any mistake I learnt from it and will remember to check it next time.

Richard Pilkington

I am a .NET Developer who is always seeking out new things and loves trying anything new. There has to be a quicker way tends to be the way I approach things

Cape Town, South Africa