dotnet / dotnet/aspnetcore

Not possible to handle/log serialization errors when returning IQueryable from an endpoint

Open
#42,849 4 comments 0 reactions 1 assignee Claimed by @rafikiassumani-msft View on GitHub
area-minimal
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Describe the bug

before i start:

It is possible that we can return an IQueryable form an endpoint. this results in a massive performance improvement especially for mass-data, since there is no in-memory object created, it's serialized "on-the-fly", like return item 1 -> discard -> return item 2 -> discard ...
of course using this behaviour we can't step in when an item can't be converted (e.g. incompatible database type), because the response is already in the process of writing

now the problem:
the frontend in this case gets success status code with a incomplete JSON array and as developers we have no way to determine what exactly is broken in the situation. we don't get a precise error message and nothing is logged at all because this seems to be out of scope for the global error handler

### Expected Behavior

There should be an Event flying for a serializer or maybe even the global exception handler should be able to process those serialization errors

### Steps To Reproduce

1. Create a test-database with a test table
2. bind a EFCore model to that database
3. create a mismatch in one of the property types.
e.g. `public Guid Id {get;set;}` receives a null-value in database
4. create an endpoint that returns an IQueryable of the above created model

you will now see the broken JSON in the frontend and no way to log or handle this exception.

### Exceptions (if any)

_No response_

### .NET Version

6.0.300-preview.22204.3

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.