0

When I'm going to add a controller. I get the following error:

enter image description here

What causes this error?

How do I solve it?

Renan Carlos
  • 290
  • 2
  • 18
  • Are getting error when you are adding a class ? – ManishKumar Aug 12 '17 at 03:49
  • The error occurs in the `Add -> Controller` . When I add the controller referencing a class as a model. – Renan Carlos Aug 12 '17 at 03:51
  • You have given us nothing to indicate what code you have that might be throwing that except, so suggest you [google](https://www.google.com.au/search?q=There+was+an+error+running+the+selected+code+generator%3A+%E2%80%98Exception+has+been+thrown+by+the+target+of+an+invocation.%E2%80%99&oq=There+was+an+error+running+the+selected+code+generator%3A+%E2%80%98Exception+has+been+thrown+by+the+target+of+an+invocation.%E2%80%99&aqs=chrome..69i57.384j0j4&sourceid=chrome&ie=UTF-8) that error message and look at the results it returns –  Aug 12 '17 at 03:52
  • One work around is, just add a class in controller folder and then inherit Controller class of mvc in your class. Now your class will be controller :) – ManishKumar Aug 12 '17 at 03:55
  • @StephenMuecke thanks for your commet, but I'm generating with visual studio scaffold. What code would it be? – Renan Carlos Aug 12 '17 at 03:56
  • Have you looked at the [first result](https://stackoverflow.com/questions/23576294/application-cant-scaffold-items) for one possible cause –  Aug 12 '17 at 03:59
  • @StephenMuecke I already tried this. – Renan Carlos Aug 12 '17 at 04:11
  • have you closed and re-opened visual studio – Jonesopolis Aug 12 '17 at 04:18
  • Reinstall Visual studio, I thinks – Dan Nguyen Aug 12 '17 at 07:52

1 Answers1

0

You need a try catch block to figure out what the real error is like so:

try{
   //your code here
}
catch(Exception e) {
   throw e;
}

Then, you can use the debugger to check what the InnerException is. You can also print out the exception message in the catch block.

Devin L.
  • 437
  • 2
  • 12