Exception has been thrown by the target of an invocation thrown when scaffolding a controller

Randell Lamont picture Randell Lamont · Jan 5, 2015 · Viewed 16.5k times · Source

I created a separate Class Library project to store the Database Context and Model Classes. In the same solution, I created an ASP.NET MVC project and referenced the Class Library project, as well as include the Connection String for the Database Context, in the project's Web.config file.

However, when I attempt to add a Controller (with views, using EF), I get the following error:

Exception has been thrown by the target of an invocation.

I am able to see the Database Context and Model Classes in the Add Controller drop down boxes, so I don't think its a referencing issue.

If anyone is also experiencing this error (with this configuration), you assistance will be greatly appreciated.

Answer

Randell Lamont picture Randell Lamont · Sep 17, 2017

I had more than one ConnectionStrings define. I removed the default and replaced it with the ConstringStrings from my Class Library. Works fine now!

Solution taken from the following post: Application can't scaffold items