diff --git a/src/Mvc/Mvc.Formatters.Xml/src/XmlDataContractSerializerInputFormatter.cs b/src/Mvc/Mvc.Formatters.Xml/src/XmlDataContractSerializerInputFormatter.cs index 8132dfdba84ec62c098b62568ec1a0873dc4524a..a2b32b23069daa5483b6448e11687c8389f28de2 100644 --- a/src/Mvc/Mvc.Formatters.Xml/src/XmlDataContractSerializerInputFormatter.cs +++ b/src/Mvc/Mvc.Formatters.Xml/src/XmlDataContractSerializerInputFormatter.cs @@ -143,6 +143,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters } readStream = new FileBufferingReadStream(request.Body, memoryThreshold); + // Ensure the file buffer stream is always disposed at the end of a request. + request.HttpContext.Response.RegisterForDispose(readStream); await readStream.DrainAsync(CancellationToken.None); readStream.Seek(0L, SeekOrigin.Begin); diff --git a/src/Mvc/Mvc.Formatters.Xml/src/XmlSerializerInputFormatter.cs b/src/Mvc/Mvc.Formatters.Xml/src/XmlSerializerInputFormatter.cs index ab3abdf801fe2c3f6e77924f5e3d23d914d769d4..66fb9aea877f565b94fecbd074f5834b38118c4a 100644 --- a/src/Mvc/Mvc.Formatters.Xml/src/XmlSerializerInputFormatter.cs +++ b/src/Mvc/Mvc.Formatters.Xml/src/XmlSerializerInputFormatter.cs @@ -124,6 +124,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters } readStream = new FileBufferingReadStream(request.Body, memoryThreshold); + // Ensure the file buffer stream is always disposed at the end of a request. + request.HttpContext.Response.RegisterForDispose(readStream); await readStream.DrainAsync(CancellationToken.None); readStream.Seek(0L, SeekOrigin.Begin); diff --git a/src/Mvc/Mvc.NewtonsoftJson/src/NewtonsoftJsonInputFormatter.cs b/src/Mvc/Mvc.NewtonsoftJson/src/NewtonsoftJsonInputFormatter.cs index ac26b61911c2308539c5b0c8f75aae8706b0a5e3..3528916b3e040b04316fcefeef78ca198212cd7d 100644 --- a/src/Mvc/Mvc.NewtonsoftJson/src/NewtonsoftJsonInputFormatter.cs +++ b/src/Mvc/Mvc.NewtonsoftJson/src/NewtonsoftJsonInputFormatter.cs @@ -153,6 +153,8 @@ namespace Microsoft.AspNetCore.Mvc.Formatters } readStream = new FileBufferingReadStream(request.Body, memoryThreshold); + // Ensure the file buffer stream is always disposed at the end of a request. + request.HttpContext.Response.RegisterForDispose(readStream); await readStream.DrainAsync(CancellationToken.None); readStream.Seek(0L, SeekOrigin.Begin); @@ -278,7 +280,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters /// <summary> /// Called during deserialization to get the <see cref="JsonSerializer"/>. The formatter context - /// that is passed gives an ability to create serializer specific to the context. + /// that is passed gives an ability to create serializer specific to the context. /// </summary> /// <returns>The <see cref="JsonSerializer"/> used during deserialization.</returns> /// <remarks> @@ -297,7 +299,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters /// <summary> /// Called during deserialization to get the <see cref="JsonSerializer"/>. The formatter context - /// that is passed gives an ability to create serializer specific to the context. + /// that is passed gives an ability to create serializer specific to the context. /// </summary> /// <param name="context">A context object used by an input formatter for deserializing the request body into an object.</param> /// <returns>The <see cref="JsonSerializer"/> used during deserialization.</returns>