My app broke with the 3.0 release of .NET core with reference errors for IdentityDbContext
. I'm looking through documentation for Identity on core 3.0 but it implies that IdentityDbContext should be there. It's the only error I'm getting with a couple DbContext
errors.
I have a pretty simple API, no MVC views, just a data server that gives back JSON objects. It's based on Identity so it has the users and roles and claims. And it's starting to take advantage of that. My main DbContext extends IdentityDbContext<ApplicationUser>
but after switching target platform to 3.0 after the upgrade, it says it doesn't exist and gives me compile errors. Has anyone run into this? Am I missing something? The migration and breaking changes pages don't seem to have anything addressing my issue.
DbContext looks like this:
using System;
using Microsoft.AspNetCore.Identity;
//using Microsoft.AspNetCore.Identity.EntityFrameworkCore; <- this no longer works either
using Microsoft.EntityFrameworkCore; //<- this I had to download as a package
using App.Constants;
using App.Models.Identity;
namespace App.Models
{
public class AppContext : IdentityDbContext<ApplicationUser> //<- error is right here
{
... my models
}
}
In ASP.NET Core 3.0, Entity Framework Core
and Identity
related packages have been removed from the Microsoft.AspNetCore.App
metapackage. So you have to add those packages separately.
Add the following PackageReference
s to your project's .csproj
file as follows:
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0" />
</ItemGroup>
Now it will work!
For more details: Assemblies removed from the ASP.NET Core shared framework
if you have an error like "error CS0246: The type or namespace name 'IdentityDbContext' could not be found" you can install bellow package for asp.net web api 3 project
dotnet add package Microsoft.AspNetCore.Identity.EntityFrameworkCore --version 5.0.0-preview.3.20215.14 in dotnet cli.its work for me.
Install-Package Microsoft.AspNetCore.Identity.EntityFrameworkCore -Version 5.0.0-preview.3.20215.14 this for package manager
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With