Make sure that the controller has a parameterless public constructor error

Dung Do Tien Aug 23 2020 150

In Asp.net core web application, I have created "ArticleController" controller and it has a constructor as below :

private IBrandBoCached _brandBoCached;
private ITextBoxSeoNewBo _texboxseoBo;
public ArticleController( IBrandBoCached brandBoCached, ITextBoxSeoNewBo texboxseoBo)
{
    this._brandBoCached = brandBoCached;
    this._texboxseoBo = texboxseoBo;
}

After running this application I got an error that An error occurred when trying to create a controller of type 'ArticleController'. Make sure that the controller has a parameterless public constructor.

Note: I used the Unity container to init all service for the application.

Thank you for any suggestions.

Have 1 answer(s) found.
  • Hello,

    I also get the same error. This error occurs when declaring some interface service error in the Unity container. Please recheck all register interface services in Unity container. Maybe  your code looks like as below, you will get this error :

    container.RegisterType<ITextBoxSeoNewBo, ITextBoxSeoNewBo>(); 

    You must change to :

    container.RegisterType<ITextBoxSeoNewBo, TextBoxSeoNewBo>(); 

    Your issue will be resolved.

    I hope this suggests helpful to you.

    Sandeep Kumar Aug 23 2020
Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips