Skip to content

Commit 222dd67

Browse files
author
John Luo
authored
Fix Unhandled DBErrors in ComponentsWebAssembly and Spa templates (#25466)
* Add workaround for EF issue dotnet/efcore#22341
1 parent 748686f commit 222dd67

File tree

4 files changed

+5
-4
lines changed

4 files changed

+5
-4
lines changed

src/Middleware/Diagnostics.EntityFrameworkCore/src/DatabaseDeveloperPageExceptionFilter.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public async Task HandleExceptionAsync(ErrorContext errorContext, Func<ErrorCont
3838
{
3939
// Look for DbContext classes registered in the service provider
4040
var registeredContexts = errorContext.HttpContext.RequestServices.GetServices<DbContextOptions>()
41-
.Select(o => o.ContextType);
41+
.Select(o => o.ContextType)
42+
.Distinct(); // Workaround for https://github.com/dotnet/efcore/issues/22341
4243

4344
if (registeredContexts.Any())
4445
{

src/ProjectTemplates/Web.ProjectTemplates/content/ComponentsWebAssembly-CSharp/Server/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ public void ConfigureServices(IServiceCollection services)
4949
#else
5050
options.UseSqlite(
5151
Configuration.GetConnectionString("DefaultConnection")));
52+
#endif
5253

5354
services.AddDatabaseDeveloperPageExceptionFilter();
54-
#endif
5555

5656
services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
5757
.AddEntityFrameworkStores<ApplicationDbContext>();

src/ProjectTemplates/Web.Spa.ProjectTemplates/content/Angular-CSharp/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public void ConfigureServices(IServiceCollection services)
4242
#else
4343
options.UseSqlite(
4444
Configuration.GetConnectionString("DefaultConnection")));
45+
#endif
4546

4647
services.AddDatabaseDeveloperPageExceptionFilter();
47-
#endif
4848

4949
services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
5050
.AddEntityFrameworkStores<ApplicationDbContext>();

src/ProjectTemplates/Web.Spa.ProjectTemplates/content/React-CSharp/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ public void ConfigureServices(IServiceCollection services)
4242
#else
4343
options.UseSqlite(
4444
Configuration.GetConnectionString("DefaultConnection")));
45+
#endif
4546

4647
services.AddDatabaseDeveloperPageExceptionFilter();
47-
#endif
4848

4949
services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
5050
.AddEntityFrameworkStores<ApplicationDbContext>();

0 commit comments

Comments
 (0)