2

I'm trying to scaffold controller for Entity Framework Core using ASP.NET Core Web API 3.1.

My database works fine, I can add new migrations and update the actual database.

The problem is that, once I install the packages and try to scaffold a new controller, the package version from 5.0.3 goes down to 3.1.12 for EntityFramework.Tools and EntityFramework.SqlServer.

What happens is that, I install the required versions of EntityFrameworkCore, EntityFrameworkCore.Design, EntityFramework.Tools and EntityFramework.SqlServer, in my case I install them as 5.0.3 version. Once installed, I'm trying to scaffold a new controller with entity framework like this:

  1. Click right mouse on the Controllers folder and click Add
  2. Select New Scaffold Item
  3. Select API Controller with actions, using EntityFramework

Unfortunately, I'm not able to create a controlled. I'm getting the error below:

There was an error running the selected Code Generator: 'Unhandled Exception: System.TypeLoadException: Could not load type 'Microsoft.VisualStudio.Web.CodeGeneration.ConsoleLogger' from assembly Microsoft.VisualStudio.Web.CodeGeneration.Core, Version=1.1.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
at Microsoft.VisualStudio.Web.CodeGeneration.Tools.Program.Main(String [] args)

What I've tried:

  1. Clearing Nuget cache
  2. Uninstalling and installing all the packages all over again
  3. Updating visual studio version
  4. Adding additional attributes to my csproj file for the actual packages.
  5. Creating a new empty project, installing the packages and scaffolding a controller. It still does not work??
  6. Reinstalling visual studio

This stack question did not help me:

ASP.NET Core 1.1.1 MVC with EF Core - not able to scaffold from controller class

I don't understand. I update my packages versions to 5.0.3 but once I try to scaffold a new controller, the package versions are being downgrade to 3.1.12 automatically.

How is this possible? Any additional ideas, how I could fix this issue?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Tadukas
  • 23
  • 7
  • I've found a solution. I've updated ASP.NET core version to 5.0 and updated all my nuget packages once again. – Tadukas Feb 27 '21 at 20:36
  • I tried to add controller scaffolding tried to install `Microsoft.EntityFrameworkCore.SqlServer` which was already installed so I went back to NuGet packages manager`Microsoft.AspNetCore.SpaServices.Extensions` version was different than rest of the packages so I upgraded following to `Microsoft.AspNetCore.SpaServices.Extensions` version number. - Microsoft.EntityFrameworkCore - Microsoft.EntityFrameworkCore.Tools - Microsoft.EntityFrameworkCore.SqlServer Rest of the packages were automatically installed during scaffolding process. – Touseef Ahmed Awan Apr 05 '21 at 12:25

0 Answers0