Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

690
Views
Does IFormFile.OpenReadStream() need to be disposed?

Should IFormFile.OpenReadStream() be called inside a using block so it's properly disposed of? Or will it be disposed of by the IFormFile after the http request finishes processing?

https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.http.iformfile.openreadstream?view=aspnetcore-5.0#Microsoft_AspNetCore_Http_IFormFile_OpenReadStream

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

The default implementation of FormFile creates a new ReferenceReadStream every time OpenReadStream() is called: https://github.com/dotnet/aspnetcore/blob/033b1fb1cf681ea95d3954c08e4391c93cd72683/src/Http/Http/src/FormFile.cs#L81

ReferenceReadStream does not contain any unmanaged resources. Calling Dispose on it is essentially a no-op. https://github.com/dotnet/aspnetcore/blob/033b1fb1cf681ea95d3954c08e4391c93cd72683/src/Http/Http/src/Internal/ReferenceReadStream.cs#L14

With that in mind, IFormFile.OpenReadStream() doesn't need to be disposed. But disposing it also doesn't hurt anything.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!