Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why Microsoft.AspNetCore.Http.FormFile does not implement IDisposable?

Microsoft.AspNetCore.Http.FormFile (link) is the default implementation of IFormFile which represents a file sent with the HttpRequest. This class contains a Stream, as such it should implement IDisposable.

How come it does not? Is there a design reason behind this?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Because FormFile is not the owner of the stream, it accepts stream (request one) as constructor parameter which is passed to it by the ASP.NET Core machinery (for example here). Request stream for example can be buffered and read multiple times or it can contain multiple files, etc. so the FormFile should not dispose it, hence it does not implement IDisposable.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading