0

I am having a simple Demo controller, but when it' s called, i have the error : "Make sure that the controller has a parameterless public constructor."

It seems to me that my code is fine:

    public class DemoController : ApiController
    {

        #region [ Global Variable Declarations ]

        private String ConnectionString = String.Empty;
        public UsersWSRepo urws;
        MailHelper MH;
        SubscriptionWSRepo sr;

        #endregion

        #region [ Constructor Initialization ]
        public DemoController()
        {
            urws = new UsersWSRepo(GlobalConstants.DBConn());
            sr = new SubscriptionWSRepo(GlobalConstants.DBConn());
            this.MH = new MailHelper();
        }

        #endregion
   }

Don' t understand where the problem comes from as it works on my other web mvc project.

what does it means make sure that the controller has a parameterless public constructor ? does it means parameters are not alowed on a webapi heritate controller ?

Nkosi
  • 235,767
  • 35
  • 427
  • 472
dtjmsy
  • 2,664
  • 9
  • 42
  • 62
  • 1
    Possible duplicate of [ASP.NET MVC: No parameterless constructor defined for this object](https://stackoverflow.com/questions/1355464/asp-net-mvc-no-parameterless-constructor-defined-for-this-object) – kuskmen Aug 11 '17 at 08:19
  • 1
    Your controller meets the requirement to have a "parameterless public constructor". Is the message just general advice issued by WebApi when it cannot find a controller? I suggest you look more broadly at the problem, for example is your controller in a separate DLL that is not loaded? – camelCase Aug 11 '17 at 08:35
  • CamelCase, you are right about the DLL that is not loaded correctly ! thanks – dtjmsy Aug 11 '17 at 10:01
  • If you found a solution for your issue, you should update the question / provide an answer so it can be closed – Andrei Matracaru Aug 11 '17 at 11:22

0 Answers0