0

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.

6
  • 1
    Are you using any type of dependency injection or IoC container? Commented Nov 25, 2013 at 21:48
  • 2
    Having public ExamplesController() {} should be the same thing as not having anything if you don't have any other constructors. Commented Nov 25, 2013 at 21:50
  • No dependencency injection or IoC container Commented Nov 25, 2013 at 21:50
  • 1
    @Clamidity true, but for the sake of the sample code, it's good to clarify that yes, it's there and yes, it's public. Commented Nov 25, 2013 at 21:54
  • Is it just this controller you're having trouble with? Are you able to create a new controller without any issues? Commented Nov 26, 2013 at 16:12

1 Answer 1

1

I have run in to similar issues when upgrading. It usually turned out to be mixed up version for assemblies in my Web.Config file.

Try this link: http://www.asp.net/mvc/tutorials/mvc-5/how-to-upgrade-an-aspnet-mvc-4-and-web-api-project-to-aspnet-mvc-5-and-web-api-2

It may not be the same upgrade, but it shows where to look for errors.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks. Those were all upgrades I needed to do. But I'm still getting the same error when trying to call that or any controller.
I'm having the same problem. Everything seems to be setup properly, but something seems wonky with Web API 2 AutoFac integration.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.