title: MemoryStream, Cannot access a closed stream
body: <p>With the <strong>sharpPDF</strong> library I generate a pdf memory stream, and I want to send it directly via email. But the line ms.Seek(.... gives an ObjectDisposedException; </p>
  
  <blockquote>
    <p>Cannot access a closed Stream.</p>
  </blockquote>
  
  <p>The pdf.CreatePDF method takes either an (output) fileName string, or an (out)Stream. But I guess it also closes the stream? I'm not used to work much with streams, so if you could please advise how it should be done? </p>
  
  <p>The sharpPDF source code of the CreatePDF method can be found here: </p>
  
  <p><a href="http://www.java2s.com/Open-Source/CSharp/PDF/SharpPDF/sharpPDF/pdfDocument.cs.htm">http://www.java2s.com/Open-Source/CSharp/PDF/SharpPDF/sharpPDF/pdfDocument.cs.htm</a></p>
  
  <pre><code>Public Sub SendPDF()
     Dim pdf As New sharpPDF.pdfDocument("Title", "Author")
  
     '....Generate pdf content
  
     Dim ms As New IO.MemoryStream
     pdf.CreatePDF(ms)
  
     Dim email As New EmailService
     email.Send(ms)
  
  End Sub
  
  Public Class EmailService
     Public Sub Send(Byval ms as Stream)
          ms.Seek(0, IO.SeekOrigin.Begin)
  
          Dim atc As New Attachment(ms, "Report.pdf")
          mail.Attachments.Add(atc)
  
          '....set other email parameters
  
          client.SendAsync(mail, mail.Subject)
    End Sub 
  End Class
  </code></pre>