Unhandled handling when using IAsyncDisposable in C# 8 with EF Core
I'm confused about I'm writing unit tests and I'm having a hard time understanding I've looked through the documentation and I'm still confused about I'm running into an unhandled exception when trying to implement the `IAsyncDisposable` interface in my C# 8 application that uses Entity Framework Core 5... I've defined a repository class that needs to manage its own database context and dispose of it asynchronously. However, when I attempt to dispose of the context within the `DisposeAsync` method, I get an `InvalidOperationException` stating that the context has already been disposed. Here's the relevant code snippet: ```csharp public class MyRepository : IAsyncDisposable { private readonly MyDbContext _context; private bool _disposed; public MyRepository(MyDbContext context) { _context = context; } public async Task<List<MyEntity>> GetAllAsync() { return await _context.MyEntities.ToListAsync(); } public async ValueTask DisposeAsync() { if (!_disposed) { await _context.DisposeAsync(); _disposed = true; } } } ``` The scenario arises when I call `GetAllAsync()` in a controller, and after processing the response, I call `DisposeAsync()` manually. The exception indicates that the context has already been disposed of. I've tried adjusting the order of operations and ensuring that DisposeAsync is not called multiple times, but I still receive the same behavior. Could this be an scenario with the lifecycle of the DbContext or the way I'm using IAsyncDisposable? Any insights on how to manage the disposal without running into this exception would be greatly appreciated. This is part of a larger API I'm building. Has anyone dealt with something similar? Has anyone dealt with something similar? I'm using C# 3.10 in this project. Could this be a known issue?