Skip to content

Why does FileHelpersAsyncEngine.Close dispose of the stream that is being written to? #434

Description

@gregveres

I realize that it is probably been like this for quite some time, but I just ran into a case where I am trying to get some information from the underlying memory stream and it is crashing because the stream was closed when FileHelpersAsyncEngine was disposed.

I have a situation like this:

Outter function() {
  using (var memory = new MemoryStream()) {
     innerFunction(memory);
     long length = memory.Length;
  }
} 

InnerFunction(Stream stream) {
            var engine = new FileHelperAsyncEngine<MyType>();
            using (engine.BeginWriteStream(stream))
            {
                engine.Close(); <= this closes the memory stream. Why?
            }
}

I am wondering why the engine.Close() method closes the stream that was passed in? The stream that was passed in isn't owned by FileHelperAsyncEngine, so why should it try to clean it up?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions