Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

There was an error running the selected code generator:

I have installed VS 2019 on my windows 10. Created ASP.net Core Web Project -> Selected API. When I try to generate controller referring the model and created the context class, It is not generating the controller class but it gives me the following error:

Error, there was an error running the selected code generator

'Unhandled exception. System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.VisualStudio.Web.CodeGeneration.Utils, Version=3.1.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified. File name: 'Microsoft.VisualStudio.Web.CodeGeneration.Utils, Version=3.1.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' at Microsoft.VisualStudio.Web.CodeGeneration.Design.Program.Main(String[] args)

like image 374
user3497702 Avatar asked Apr 26 '20 14:04

user3497702


3 Answers

I also had this problem but the follwing answer worked for me. Select "Manage Nuget Packages" and install these packages

<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration" Version="3.1.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.1.2" ExcludeAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Utils" Version="3.1.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGenerators.Mvc" Version="3.1.2" />
like image 106
Akın Kaplan Avatar answered Nov 07 '22 01:11

Akın Kaplan


To solve the problem, you can right click on your project, then select Manage Nuget Packages.

Next, Search Microsoft.VisualStudio.Web.CodeGeneratio.Utils, then install it.

After installing the above, It is generating without error.

like image 3
user3497702 Avatar answered Nov 07 '22 02:11

user3497702


First, check your csproj file. There is no package reference for 'Microsoft.VisualStudio.Web.CodeGeneration.Utils, Version=3.1.2.0'. This is why the error message showing "Could not load file or assembly". Easy to solve. https://www.nuget.org/packages/Microsoft.VisualStudio.Web.CodeGeneration.Utils/ Go to Package Manager Console install it.

like image 1
Daisy Avatar answered Nov 07 '22 00:11

Daisy