diff --git a/src/Mvc/Mvc.Formatters.Xml/src/XmlDataContractSerializerInputFormatter.cs b/src/Mvc/Mvc.Formatters.Xml/src/XmlDataContractSerializerInputFormatter.cs index 8132dfdba8..a2b32b2306 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 ab3abdf801..66fb9aea87 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 ac26b61911..3528916b3e 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 /// /// Called during deserialization to get the . 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. /// /// The used during deserialization. /// @@ -297,7 +299,7 @@ namespace Microsoft.AspNetCore.Mvc.Formatters /// /// Called during deserialization to get the . 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. /// /// A context object used by an input formatter for deserializing the request body into an object. /// The used during deserialization.