Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The message "An exception occurred while iterating over the results of a query for context type 'X'." can not be caught #1938

Open
Nefcanto opened this issue Aug 14, 2024 · 0 comments

Comments

@Nefcanto
Copy link

File a bug

Include your code

Create a context, a database, and models. Then make a difference between the database and the EF Core model. Then run any code to read from the database:

using var context = new SomeContext();
var items = context.SomeItem.ToList();

You end up with an exception like this:

fail: 08/14/2024 07:29:05.687 CoreEventId.QueryIterationFailed[10100] (Microsoft.EntityFrameworkCore.Query) 
      An exception occurred while iterating over the results of a query for context type 'SomeContext'.

No matter where I put try/catch blocks, I can't catch this message. It seems that this message is internal to the EF Core and it catches it internally, logs it, and then rethrows it.

I need to be able to extract the context name from this message. Either report back the name of the context, or somehow let us catch this exception.

Include provider and version information

EF Core version: 8.0.2
Database provider: Pomelo.EntityFrameworkCore.MySql
Target framework: net8.0
Operating system: Debian GNU/Linux 12 (bookworm)

I have also reported it to the EF Core team dotnet/efcore#34430

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant