Related to #48322 and #46349.
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.
Related to #48322 and #46349.
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):
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.