You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
System.Text.Json not properly disposing enumerators on exceptions #50851
area-System.Text.JsonenhancementProduct code improvement that does NOT require public API changes/additionshelp wanted[up-for-grabs] Good issue for external contributorsin-prThere is an active PR which will close this issue when it is merged
The current IEnumerable converters don't dispose of enumerators in certain scenaria where nested element converters throw exceptions. Reproducing test (using a few System.Text.Json.Tests components):
[Fact]publicstaticvoidWriteIEnumerableT_ElementSerializationThrows_DisposesEnumerators(){varitems=newRefCountedList<IEnumerable<int>>(Enumerable.Repeat(ThrowingEnumerable(),1));Assert.Throws<DivideByZeroException>(()=>JsonSerializer.Serialize(items.AsEnumerable()));Assert.Equal(0,items.RefCount);// items.RefCount evaluates to 1staticIEnumerable<int>ThrowingEnumerable(){yieldreturn42;thrownewDivideByZeroException();}}
Note that #50778 makes changes to the serialization infrastructure to handle IEnumerator disposal in the async case, however changes on the individual converter level will still need to be made. cc @layomia@steveharter.
area-System.Text.JsonenhancementProduct code improvement that does NOT require public API changes/additionshelp wanted[up-for-grabs] Good issue for external contributorsin-prThere is an active PR which will close this issue when it is merged
Activity
steveharter commentedon Aug 4, 2021
Suggest moving to 7.0. No community asks that I'm aware of.
eiriktsarpalis commentedon Aug 16, 2021
Note that this should be fixed for Dictionary converters as well.
eiriktsarpalis commentedon Apr 18, 2022
Moving to Future, as we won't have time to work on this in the .NET 7 timeframe.
eiriktsarpalis commentedon Jun 24, 2024
After deliberation we've decided to not fix this bug. It is largely a theoretical concern that no user has reported so far.