How can I resolve Error Running the Selected Code Generator when adding scaffolded item

145 views Asked by At

I have looked at all the questions about this issue and cannot seem to resolve it.

Visual Studio 2022. .Net 6.0.15. Blazor.

enter image description here

I am trying to scaffold identity to one of my projects (Server) in the solution. I will also scaffold the WASM project but can't get the Server done. I haven't tried the WASM yet. I downgraded from 6.0.16 to 6.0.15 to match the Microsoft.VisualStudio.Web.CodeGeneration (max version available is 6.0.15) packages but that didn't help. I tried upgrading to 6.0.20 with no joy. I posted all the packages in case someone can see a conflict. I'm not sure it is a package problem but it will not let me scaffold identity which I think is a fairly basic scaffolding operation.

This error pops up it appears as soon as the Microsoft.EntityFramework.Tools begins to execute.

Project Packages:

API:

<PropertyGroup>
   <TargetFramework>net6.0</TargetFramework>
   <Nullable>enable</Nullable>
   <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
   <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
   <PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>

Business:

<PropertyGroup>
   <TargetFramework>net6.0</TargetFramework>
   <ImplicitUsings>enable</ImplicitUsings>
   <Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
   <PackageReference Include="AutoMapper" Version="12.0.1" />
   <PackageReference Include="Blazor.Bootstrap" Version="1.7.3" />
   <PackageReference Include="System.Diagnostics.EventLog" Version="7.0.0" />
</ItemGroup>

DataAccess:

<PropertyGroup>
   <TargetFramework>net6.0</TargetFramework>
   <ImplicitUsings>enable</ImplicitUsings>
   <Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
   <PackageReference Include="AutoMapper" Version="12.0.1" />
   <PackageReference Include="Blazor.Bootstrap" Version="1.7.3" />
   <PackageReference Include="Microsoft.AspNetCore.Authorization" Version="6.0.15" />
   <PackageReference Include="Microsoft.AspNetCore.Components" Version="6.0.15" />
   <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.15" />
   <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.15">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
   </PackageReference>
   <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.15" />
   <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.15">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
   </PackageReference>
   <PackageReference Include="System.Diagnostics.EventLog" Version="7.0.0" />
</ItemGroup>

Models:

<PropertyGroup>
   <TargetFramework>net6.0</TargetFramework>
   <ImplicitUsings>enable</ImplicitUsings>
   <Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
   <PackageReference Include="Blazor.Bootstrap" Version="1.7.3" />
   <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.15">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
   </PackageReference>
   <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.15" />
   <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.15">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
   </PackageReference>
   <PackageReference Include="System.Diagnostics.EventLog" Version="7.0.0" />
</ItemGroup>

Server:

<PropertyGroup>
   <TargetFramework>net6.0</TargetFramework>
   <Nullable>enable</Nullable>
   <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
   <PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
   <PackageReference Include="BitMiracle.Docotic.Pdf" Version="8.8.14015" />
   <PackageReference Include="Blazor.Bootstrap" Version="1.7.3" />
   <PackageReference Include="Microsoft.AspNetCore.Authentication.Negotiate" Version="6.0.15" />
   <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="6.0.15" />
   <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.15">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
   </PackageReference>
   <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.20" />
   <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.15">
      <PrivateAssets>all</PrivateAssets>
      <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
   </PackageReference>
   <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration" Version="6.0.15" />
   <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.15" />
   <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Utils" Version="6.0.15" />
   <PackageReference Include="PSC.Blazor.Components.BrowserDetect" Version="1.0.11" />
   <PackageReference Include="System.Diagnostics.EventLog" Version="7.0.0" />
</ItemGroup>

WASM:

<PropertyGroup>
   <TargetFramework>net6.0</TargetFramework>
   <Nullable>enable</Nullable>
   <ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
   <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="6.0.15" />
   <PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="6.0.15" PrivateAssets="all" />
   <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
</ItemGroup>
2

There are 2 answers

1
Steve Cross On

As you can see in my above packages, SQLServer is set to 6.0.20. It was doing this as soon as I started scaffolding. I had changed it to 6.0.15 to match everything else but I didn't notice this was changing. So, I moved everything in AspNetCore and EntityFrameworkCore back to 6.0.20 and it worked. I can only surmise that when I tried it at 6.0.20 before, I had missed something. The long and the short, it was package version mismatches. I found this by going through the Dependencies-Packages manually and I saw the version mismatch. I tried to convert it back to 6.0.15 but as soon as I started the scaffolding operation, it changed back. This led me to changing all packages to 6.0.20 and it finally worked. Thank you for taking your time to read this issue and I hope it helps someone in the future.

0
KSK On

In addition to Steve's note, I suggest you upgrade your packages only to the latest version on your target sdk. Writing in 2024 when .net 8 has already been released, I'm fixing this issue for a .net 6 sdk project. I upgraded all my relevant packages to 6.0.28 even though 8.0.3 is the latest available.