I just recently upgraded my project from VS2010 and .NET 4.0 to VS2013 and .NET 4.5.1
After fixing a lot of other assembly reference and dependency issues with most of the packages, I can't get my controllers to work anymore. Here is the stack trace error I'm getting:
ExceptionMessage=An error occurred when trying to create a controller of type 'ExamplesController'. Make sure that the controller has a parameterless public constructor.
From what I've read elsewhere, this is a common problem, although I never needed a parameterless constructor in ANY of my constructors prior to upgrading to .NET 4.5.1 and Web Api 2.
Here is what I changed my controller to:
public class ExamplesController : ApiController
{
static readonly IVehicleRepository repository = new ExampleRepository();
public ExamplesController() {}
// GET api/v1/examples
public HttpResponseMessage GetExamples()
//etc etc
Yet I'm still getting the aforementioned error when I try to test on this controller.
What else could be going on here. Something in my Web.config?
Thank you.
Edit:
Here is the StackTrace that went along with the top most error in my Response header:
StackTrace= at System.Web.Http.Dispatcher.DefaultHttpControllerActivator.Create(HttpRequestMessage request, HttpControllerDescriptor controllerDescriptor, Type controllerType)
at System.Web.Http.Controllers.HttpControllerDescriptor.CreateController(HttpRequestMessage request)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.SendAsyncCore(HttpRequestMessage request, CancellationToken cancellationToken)
at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__0.MoveNext()
Edit2: This is coming up in my Error List when I try to build the project:
Warning 2 Found conflicts between different versions of the same dependent assembly that could not be resolved. These reference conflicts are listed in the build log when log verbosity is set to detailed. TrackStarServices
Error 1 'System.Web.Http.GlobalConfiguration' does not contain a definition for 'Configure' C:\Projects\AVLS-Web-Services\TrackStarServices\Global.asax.cs 21 33 TrackStarServices
I have the build log (it's big) if anyone would like to see any parts of it.
Ok, after fixing references and reinstalling packages all over, I think the MAIN culprit was that EntityFramework was targeting version 6.0.0.1 and not 6.0.0.0.
Just changed that to reference the top level version and now all the controllers work properly. Waste of a day. Thanks everyone.