1

I got a problem two days ago while working on a project.

When I try to create a new controller or a view by hovering over the View() method and then clicking "Add View", VS generates nothing and no error message but these lines :

Finding the generator 'controller'...
Running the generator 'controller'...
Attempting to compile the application in memory.
   at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.<BuildCommandLine>b__6_0()
   at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.Execute(String[] args)
   at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)

I tried to update VS to latest version which is now 16.4.3 Community edition but with no luck.

Tried to reinstall Microsoft.VisualStudio.Web.CodeGeneration from NuGet but no luck again.

Tried to delete .vs folder and no luck again.

What could be the problem? It was working normally before that but the scaffolding stopped working.

Thank you

5
  • First, you need to verify if your problem is visual studio specific or something on your machine. For example, download Rider and try it with that tool. jetbrains.com/rider/download/#section=windows . Very likely it is but you need to know for sure. You can also use Visual studio code instead; code.visualstudio.com/docs/languages/dotnet . If it is VS specific, you can repair VS with VS Repair inside the installer. learn.microsoft.com/en-us/visualstudio/install/… . Good luck. Commented Jan 25, 2020 at 17:59
  • @Daan Thank you but any of these options has an option to create a controller using EF ? Like Add => Controller => Controller using EF for auto generation controller with actions and views ? Because I can easily add an empty controller and an empty view, but my problem is adding a new controller using EF Commented Jan 25, 2020 at 18:20
  • And unfortunately, repairing VS didn't solve the problem. Commented Jan 25, 2020 at 18:33
  • Yes, you can generate controllers in Rider too: stackoverflow.com/a/57000703/1987258 . In addition, VS Code has an extension to help you with that. marketplace.visualstudio.com/… Commented Jan 25, 2020 at 18:33
  • I can generate a controller, but without EF in both choices unfortunately. Rider generate an empty controller. My problem is generating them using EF to generate the Controllers with action names and views which I can modify later. But right now, I have so many models which I need to generate code for. And no time to write all the controllers and views it from scratch. Any other option here ? Commented Jan 25, 2020 at 18:45

3 Answers 3

4

It turns out it has something with a certain c# language syntax. Reading this issue on GitHub helped me to find a workaround.

What helped me fixing the problem is this comment:

By adding this package:

Microsoft.CodeAnalysis.CSharp.Workspaces

In the comment, the package version was 3.3.1, but I installed 3.4.0 and it works like a charm.

Sign up to request clarification or add additional context in comments.

2 Comments

I had the same issue but .NET core 3.1 and web API application. Your solutions worked like a charm.
Thanks for the help @Kaj i had a similar issue for .net 5 and it is resolved using this
0

I had the same issue. Ubuntu 18.04.5 LTS, Rider EAP 2020.3. C# 9, dotnet-aspnet-codegenerator version '5.0.1', dotnet 5.0.102.

Finding the generator 'controller'...
Running the generator 'controller'...
Attempting to compile the application in memory.
Attempting to figure out the EntityFramework metadata for the model and DbContext: 'Person'
A file matching the name MvcControllerWithContext.cshtml was not found within any of the folders: 
   at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.<BuildCommandLine>b__6_0()
   at Microsoft.Extensions.CommandLineUtils.CommandLineApplication.Execute(String[] args)
   at Microsoft.VisualStudio.Web.CodeGeneration.ActionInvoker.Execute(String[] args)
   at Microsoft.VisualStudio.Web.CodeGeneration.CodeGenCommand.Execute(String[] args)

In desperation mode started trying everything and ran into this and it worked with my configuration.

Comments

0

In my case I fixed it changing the target of the project to "Net 5.0" (I know this is not always posible) and after that, through (Tools/Manage Nuget Packages) updating these packages to the latest version (in this moment is 5.0.9):

  • Microsoft.EntityFrameworkCore
  • Microsoft.EntityFrameworkCore.SqlServer
  • Microsoft.EntityFrameworkCore.Tools

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.