User class entry is disabled in Add Identity dialog box

Viewed 316

I'm trying to scaffold some identity pages. But while I can select the files to override and select my database context class, the box to select my user class is disabled.

Add Identity Dialog Box

And attempting to add the scaffolding without setting the user class produces an error.

There was an error running the selected code generator:

'Package restore failed. Rolling back package changes for 'Railtrax'.'

This scaffolding feature fails for me about 90% of the time. I don't know why it can't be made more reliable.

Note that I do define my user class.

public class ApplicationUser : IdentityUser
{
    // ...
}

And I reference it in my database context class.

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
    // ...
}

So I don't understand why it won't work. Can anyone see what I might be missing?

2 Answers

i ran into this error and had to role back the identity Microsoft.AspNetCore.Identity.UI to an older version

so it looks like this in the csproj

          <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.2" />
            <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.2" />
            <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.2">
    
     
        <PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.6" />
        <PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="5.0.6" />
       
        <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="5.0.7">
  </PackageReference>
        <PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.6" />
        <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.6">
          <PrivateAssets>all</PrivateAssets>
          <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
        </PackageReference>
        <PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="5.0.2" />

I have run in the same error as well. It is not due to your User class. Actually, if you enter your Db Context in that window manually pressing "+" it will allow you to find the User class, but you will still get the same error. The issue is with your CodeGenerator. I tried installing different versions of CodeGenerator, but it didn't help. I did however found a way to scaffold identity that works. Run the command line in your project folder.

dotnet tool install -g dotnet-aspnet-codegenerator

If you have it installed then run

 dotnet aspnet-codegenerator identity --help 

to see all the arguments. or just run

dotnet aspnet-codegenerator identity -dc MyApplication.Data.ApplicationDbContext --files "Account.Register;Account.Login"

-dc showing the path to your application context and --files if you want just specific pages, but I just run without it and then deleted the pages I didn't want.

Related