12

I'm trying to generate Identity Account\Login and Account\Register pages in a new project. I've tried both .NET Core 3.1 and .NET 5; in both cases, even when it's a new project, I receive the following error message:

enter image description here

An incredibly helpful error message, as you can tell. Does anybody know what can cause this with .NET Core 3.1 or .NET 5 projects and how to fix it? I've got VS2019 v16.9.5 installed, Microsoft's IdentityServer v.5.0.6, EntityFrameworkCore v.5.0.6, Identity.UI v5.0.6, and CodeGeneration.Design v.5.0.2 all installed for my .NET 5 project, and whatever the default versions of those packages for the new .NET Core 3.1 project. Both projects fail to correctly scaffold the needed files.

6 Answers 6

15

I found a workaround for this error by using the dotnet CLI outside of Visual Studio to execute the scaffolding tool. The following steps use the aspnet-codegenerator tool to scaffold the full Identity pages area into your .Net Core 5 app.

1.Close Visual Studio.

2.Open a command prompt and change directories to the project location.

3.Make sure the aspnet-codegenerator tool is installed on your machine by executing this command:

dotnet tool install -g dotnet-aspnet-codegenerator

4.Add Microsoft.VisualStudio.Web.CodeGeneration.Design package to the project if it does not already exist in your project.

Install-Package Microsoft.VisualStudio.Web.CodeGeneration.Design

5.Run the following command where YourAppName.Models.ApplicationDbContext is the namespace to your DbContext:

dotnet aspnet-codegenerator identity -dc YourAppName.Models.ApplicationDbContext

If the command completed without errors that should have fixed the “There was an error running the selected code generator” issue and created the necessary Identity Pages under Areas/Identity/Pages.

enter image description here

dotnet aspnet-codegenerator also has the ability to scaffold only specific files versus all the Identity files if you don’t need the full set by passing in the -files parameter followed by the files you want to create.

dotnet aspnet-codegenerator identity -dc MyApp.Models.ApplicationDbContext –files “Account.Register;Account.Login;Account.Logout”

Further you need to add following packages in project Microsoft.AspNetCore.Identity.UI,Microsoft.EntityFrameworkCore.Design

2
  • 1
    I'm testing this answer out and looking into @JamieD77's answer as well. I'd like to use .NET 5, although his answer sounds sensible for .NET Core 3.1. I tested your answer in a new .NET 5 project and it's looking good. I'm wondering if your answer here has anything to do with what's causing the issue here: stackoverflow.com/questions/67498016/…
    – KSwift87
    May 13, 2021 at 4:53
  • I get the "Scaffolding Identity is not supported for web applications with minimal APIs for hosting and routing." error again ...
    – 91378246
    Sep 1, 2021 at 7:34
4

Following up on JamieD77's answer, if you have this issue on .net 5, simply downgrade Microsoft.AspNetCore.ApiAuthorization.IdentityServer and Microsoft.AspNetCore.Identity.UI to version 5.0.0. The scaffold will now work.

1
  • Worked like a charm! Thanks!
    – JakeL
    Sep 27, 2021 at 22:59
3

Closing the project and deleting the bin and obj folders worked in my case.

2

I ran into this yesterday.

What I had to do was install version 3.1.13 of Microsoft.AspNetCore.ApiAuthorization.IdentityServer and then Microsoft.AspNetCore.Identity.UI and after that, the scaffolding worked in VS2019

All of my AspCoreNet packages were set to 3.1.15 previously.

1
  • I was facing the same problem from last one day , search every page on internet but Only yours's solution works! by downgrading to Microsoft.AspNetCore.ApiAuthorization.IdentityServer and Microsoft.AspNetCore.Identity.UI to 3.1.13
    – Saveen
    Aug 13, 2021 at 17:39
0

For me it solved when update the entity framework core to the latest version

0

For dotnet 6 just upgrade all identity and ef core related libraries to version 6.x.x. Also the database ef core libraries.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.