-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
IAsyncEnumerableOfTConverter<TAsyncEnumerable, TElement> throws OutOfMemoryException when custom JsonConverter involved #102984
Comments
Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis |
Presumably each individual element is too large to fit in-memory? This is a known restriction of custom converters that do not support streaming, and is not directly related to IAsyncEnumerable. This is being tracked by this issue #63795 |
Each individual element is not too large to fit into memory. But rather, ShouldFlush never returns true and the collection keeps getting bigger in the buffer, never being flushed out to the caller. |
Can you share a repro? |
I'll be able to provide one later tomorrow. I'll ping you as soon as I got one running! |
Thanks, would appreciate if it could be made as minimal as possible, preferably a small console app. |
This issue has been marked |
You mentioned Ignoring that discrepancy... from your code you have a similar pattern in your Write method to a similar issue #66102 which has been fixed in 9.0. |
This issue has been automatically marked |
This issue will now be closed since it had been marked |
If a consumer has defined a custom JsonConverter for an interface, to allow polymorphism, for example something like this:
And you then try to return it as an
IAsyncEnumerable<ICustomInterface>
, you end up getting anOutOfMemoryException
because the content is never flushed by theIAsyncEnumerableOfTConverter<TAsyncEnumerable, TElement>
.Workarounds
Using
IAsyncEnumerable<object>
without a customJsonConverter<>
works as expected. You can then use the customJsonConverter<>
in the client code to consume it as an interface type, like so:Is this expected?
The text was updated successfully, but these errors were encountered: