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.

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