Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
"Microsoft.Usage", "CA2202:Do not dispose objects multiple times"
using (var stream = new MemoryStream())
using (var writer = new StreamWriter(stream) { AutoFlush = true })
{
writer.Write(message.Xml);
stream.Seek(0, SeekOrigin.Begin);
this.documentSession.StoreAttachement(
"someId", null, stream, new RavenJObject { { "Content-Type", "application/xml" }, });
}
@mtrainham

This comment has been minimized.

Copy link

@mtrainham mtrainham commented Jan 17, 2013

If I had to guess, I'd say stream is being disposed within writer first when writer is disposed, and then again after stream's using statement ends, so just create the stream without a using statement.

using (var writer = new StreamWriter(new MemoryStream()) { AutoFlush = true })
{
    writer.Write(message.Xml);

    stream.Seek(0, SeekOrigin.Begin);

    this.documentSession.StoreAttachement(
        "someId", null, stream, new RavenJObject { { "Content-Type", "application/xml" }, });
 }
@hedoluna

This comment has been minimized.

Copy link

@hedoluna hedoluna commented Dec 9, 2014

It's equal to the official MSDN documentation: http://msdn.microsoft.com/it-it/library/ms182334.aspx

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