Skip to content

Duplicate DBContextOptions registered in DI #22341

@JunTaoLuo

Description

@JunTaoLuo

While debugging a failure in our blazorwasm templates with individual auth using local databases, I encountered an issue that broke DatabaseDeveloperPageExceptionFilter. Specifically it seems like two instances of DBContextOptions<ApplicationDBContext> were registered in DI. This eventually caused an issue where FinalizeModel was called twice and it threw on the second call. While we can workaround the issue by deduping the context options in the exception filter, it seems like a bug that two context options were registered in the first place.

I'm assigning @smitpatel since he helped me debug this issue and has some context so he can help fill in the blanks in case I missed some details.

Steps to reproduce

Repro: https://github.com/JunTaoLuo/DuplicateContext
Run the project and set a breakpoint in DatabaseDeveloperPageExceptionFilter to observe the duplicated dbcontexts.

Further technical details

EF Core version: 5.0.0-rc.1.20430.4
Database provider: e.g. Microsoft.EntityFrameworkCore.SqlServer
Target framework: net5.0
Operating system:
IDE:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions