There was an error running the selected code generator: 'Object reference not set to an instance of an object'
Steps to reproduce
- Create Code-First model, I called it MyModel with a single property MyModelID
- Right click on Controllers, choose Add controller
- Choose MVC Controller with views, using EF
- Choose Add
- Error
Expected behavior
- Controller and Views to be created
Actual behavior
Error
There was an error running the selected code generator: 'Object reference not set to an instance of an object'
Environment data
Visual Studio 2017 .Net Core 2.1.4 Microsoft.VisualStudio.Web.CodeGeneration.Design (v2.0.1)
It seems that the data context does not default anymore and out of habit I did not even bother, but choosing a context now seems to eliminate this issue.
Hey! I don't know whether this issue was solved or not, but I was facing the same problem while creating empty API Controller. What helped in my case is that I had wrong CodeGeneration.Design package installed, so I went to nuget package manager and deleted my CodeGeneration.Design package and then when tried to scaffold new controller it installed the required CodeGeneration.Design package itself. In case you are looking for the package itself it is Microsoft.VisualStudio.Web.CodeGeneration.Design