I get this error
An error occurred when trying to create a controller of type 'AnalyticController'. Make sure that the controller has a parameterless public constructor.
Code works in test environment but not on the production server.
Any idea what could cause the problem?
This is my controller
public class AnalyticController : ApiController
{
private AnalyticBLL analyticBLL = new AnalyticBLL();
// POST api/status
public void Post(AnalyticDTO analyticDTO)
{
if (!analyticBLL.Register(analyticDTO))
helpers.BusinessLayer.CreateResponseException(analyticBLL.Errors);
}
}
I was getting this error because I had an Exception occurring in my parameter-ful constructor. It had nothing to do with requiring a parameter-less constructor despite the error message.
That depends on how you're handling DI (dependency injection). By default, controllers need paramaterless constructor, and you have to use something like Unity or Ninject to handle DI. I see you're inhereiting from ApiController, so if you're using Ninject make sure you download Ninject for Web API. If you already know everything I just told you, then you need to give more information. What's your setup? What are you using for DI?
Add a public parameterless constructor and the problem goes away:
public class AnalyticController : ApiController
{
public AnalyticController()
{
}
// Variables and methods are the same as before
}
Don't know if this will help anybody else. I build & then run my app against web services all on my local (dev) box. Then before I deploy to production, I run my app pointing to the existing production web services. This usually works, but this time, it worked "in dev" but gave me this "Make sure that the controller has a parameterless public constructor" error message "in production" (well, not really in production but against the production web services).
None of these solutions seemed like the problem for my code and when I deployed my code to production, I did not get this error when it is all in production. My guess is that it may have to do with different versions of the NuGet packages between my dev box & production. I'll investigate, I but just wanted to offer this up in case others have a similar "works against dev but not prod" situation. It may be an environment issue (depending on what you mean by does not work "in prod").
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With