asp.net-core.net-5.net-core-2.1

Upgrading from .NET Core 2.1 to .NET 5.0 shows an error: 'IApplicationBuilder' does not contain a definition for 'UseDatabaseErrorPage'


Can anyone provide a solution for the below error that I'm getting when Upgrading from .NET Core 2.1 to .NET 5.0:

'IApplicationBuilder' does not contain a definition for 'UseDatabaseErrorPage' and no accessible extension method 'UseDatabaseErrorPage' accepting a first argument of type 'IApplicationBuilder' could be found (are you missing a using directive or an assembly reference?)

Microsoft Doc says its obsolete: https://learn.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.builder.databaseerrorpageextensions.usedatabaseerrorpage?view=aspnetcore-5.0

Below reference from Microsoft page does not work on 5.0: https://github.com/aspnet/Announcements/issues/432


Solution

    1. Add this NuGet package: Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore

      enter image description here

    2. Add a using statement for Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore

    3. Add this middleware: app.UseDeveloperExceptionPage();