Blazor Server: Cannot access a closed Stream
I'm trying to export a list of objects to a csv and then make the user download it. I'm getting an error for having the stream closed. If I remove all the
using
in GetFileStream
I end up getting another error for Javascript not found
1 Reply
this is the problem
because you're
using
the memory stream here, it's disposed when this method returns
you need to wait to dispose it until you're done using it in the calling code
i think you'll also need to use the StreamWriter constructor that lets you specify leaveOpen
because otherwise it will close the underlying stream when it's disposed too
also potentially seek the stream back to the beginning