• Register
1 vote
197 views

Problem :

Recently I was told to prepare the C# as I am in pool of new projects. So I have started learning C#. But because of some unknown reason to me now I am facing below error.

Make sure that the controller has a parameterless public constructor”.

As I am very new to C# so I am unable to understand the above error.

I need help from someone who can fix the above error.

8 5 2
3,230 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution :

I can tell you what must have happened with you is that you must have forgotten to register your controllers explicitly in the container. Now the Unity will try to fix the unregistered concrete types for you but as it is unable to resolve it so it will return null. Now the Web API will try to create your controller itself but as it does  not have the default constructor in this case it will throw the above error listed by you.

This error message is certainly misleading for beginners like you and it fail to explain you the real cause.

This is the configuration error and it comes because of adding the second constructor to the DbContext. Now the Unity will try to pick a constructor which is having the most arguments, but here it has no idea how to fix this particular constructor.

It seems you are trying to use a Unity's auto wiring capabilities simply to create a DbContext. I must tell you the DbContext is the most special type and so it shouldn't be auto wired. As it is the framework type so you should fallback to the registering it using the factory delegate.

 

8 4
5,680 points

Related questions

0 votes
1 answer 8 views
8 views
Problem: the requested resource does not support http method 'get'.
asked Feb 20 charles mathews 3.8k points
1 vote
1 answer 49 views
49 views
Problem : While binding the dropdown in MVC, I often face following error: There is no ViewData item of type 'IEnumerable<SelectListItem>' that has the key country. Please find below my View for your reference : @Html.DropDownList("country", (IEnumerable<SelectListItem>)ViewBag ... .countryid.ToString() }); } ViewBag.mycountrydrop = myitem8; return View(); I do not know how to resolve above error.
asked Dec 28, 2019 alecxe 7.5k points
0 votes
1 answer 128 views
128 views
Problem : I have recently installed a website on my local machine using IIS 7 successfully. But when I tried to deploy it on the live server, I got a following error: "The page cannot be displayed because an internal server error has occurred" Nothing else. Using a same IIS 7 on live and also set to have the Detailed errors in Error Pages module, but still getting a same. What can be the reason?
asked Jan 28, 2020 jwilliam 3.9k points
0 votes
1 answer 18 views
18 views
Problem: I am trying to enable CORS on one of the very specific actions in my Asp.net Web Api. Please find below my code and tell me if I am missing anything: [Route("api/mycontroller/myaction")] [HttpPost] [EnableCors("https://example.com", "*", "post")] public ... http method 'OPTIONS'." I also tried to remove the [HttpPost] annotation but to no avail. Have I made any mistake in my above code?
asked Aug 19, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 10 views
10 views
Problem: are you missing a using directive or an assembly reference.
asked Feb 18 charles mathews 3.8k points
0 votes
1 answer 10 views
0 votes
1 answer 24 views
24 views
Problem: I am naive to Asp.Net.I am having a weird looking problem where I am trying to open up my ASP.NET MVC application but I am receiving the below ASP.NET error page which says: Server Error in '/' Application. The resource cannot be found. Description: ... unknown reason to me it seems like it is actually searching for the .aspx file. Please guide me if you think I am missing something.
asked Aug 19, 2020 Raphael Pacheco 4.9k points
0 votes
1 answer 4 views
4 views
Problem: This request has been blocked; the content must be served over https.
asked Feb 15 Ethan ross 1.8k points
0 votes
0 answers 9 views
9 views
Problem: cara mengatasi datatables warning table id table ajax error
asked Feb 17 Dan phillip 1.9k points
0 votes
1 answer 1.6K views
1.6K views
Problem : I am facing the below error: Failed to load resource: the server responded with a status of 401 (Unauthorized) http://localhost/App/AngularJS/angular.min.js My project works fine on the localhost. But when I try to run it on the IIS (7.5) I often face ... read/write/modify access for the "IUSR" & "IIS_ISURS" users of my whole project. But still I am facing the same exception on my IIS.
asked Dec 24, 2019 alecxe 7.5k points