AddIdentity() fails "InvalidOperationException: Scheme already exists: Identity.Application"
I had a similar issue. This might be more helpful for people using .Net Core 3.0. After digging around I found out that once you create an "Identity" area using scaffolding. A file called "IdentityHostingStartup.cs" is created inside the Identity folder.
Inside the class, another instance of "AddDefaultIdentity" is created along with a few other services.
If you remove the "addDefaultIdentity" from your "Startup.cs" your app should start. Also, If you are getting a null connection string error. Update the connection string inside of the IdentityHostintgStartup.cs
Note: Deleting either of the addDefaultIdentities will work. You just can't have it in both locations.
Hope this helps.
I also had the same problem.
I found out that services.AddIdentity<ApplicationUser, ApplicationRole>()
in 2 places.
I removed one of them and now everything works as expected.
I had the same issue, I was registering services in two different files in the same time: Startup.cs and IdentityHostingStartup.cs files.
What I did?
I sepeprated registering the services in both files as following:
IdentityHostingStartup.cs
I only registered Identity DB Context in this file:
//lets register identity db context
builder.ConfigureServices((context, services) => {
services.AddDbContext<IdentityDbContext>(options =>
options.UseSqlServer(
context.Configuration.GetConnectionString("IdentityDBConnection"),
x => x.MigrationsAssembly("WebApplication1")
)
);
Startup.cs
In this file I registered DefaultIdentity, Roles and EntityFrameworkstores
//I registered the DefaultIdentity, the Roles and the EntityFrameworkstores
services.AddDefaultIdentity<IdentityUser>(options => options.SignIn.RequireConfirmedAccount = true)
.AddRoles<IdentityRole>().AddEntityFrameworkStores<IdentityDbContext>();