When you create a new Facades.Form object with the (sourceStream, DestStream) constructor, the sourceStream object gets disposed when you call theObject.Save();
It is a general rule of C# that the creator of a disposable object, are responsible for disposing it. ( http://msdn.microsoft.com/en-us/library/3bwa4xa9.aspx - http://stackoverflow.com/questions/1041267/net-streams-passing-streams-between-objects-best-practices-c
)
Not only do I think that this new behavior is bad ( not only because it broke some of our code, that made good assumptions ), you guys changed from the old behavior, silently. Pdf.Kit.Form(sourceStream, DestStream) did not do this.
The worst part is the silent part. You guys don’t think this is important to document? It could have been written here: http://www.aspose.com/documentation/.net-components/aspose.pdf-for-.net/aspose.pdf.facades.form.save.html , or here: http://www.aspose.com/documentation/.net-components/aspose.pdf-for-.net/aspose.pdf.facades.formconstructor1.html
, but it wasn’t.
Why this may be a big deal is because it’s conceivable that a developer would want to reuse a stream, especially one that is able to be reset back to the beginning. This example code no longer works in the new Facades.Form:
using( var sourcePdfStream = new MemoryStream( File.ReadAllBytes( sourcePdfFilePath ) ) ) {
// Per copy of the source pdf file that needs to be merged
foreach( var row in rowTree ) {
var stream = new MemoryStream();
// save this stream for later since I’m supposed to be responsible for disposing it
streams.Add( stream );
// This crashes on the second iteration, because sourcePdfStream will be disposed.
var doc = new Aspose.Pdf.Facades.Form( sourcePdfStream, stream );
// Do some stuff to the doc
doc.Save(); // Now, my sourcePdfStream is disposed, when I don’t want it to be.
}
// dispose my streams in streams
}
I don’t require a reply telling me how to get around this- I’m aware of how to change my code to get it to work. The point is that I don’t think it was a good change on your behalf, and it’s even worse that it’s not documented behavior. You’re now supporting users who carelessly create resource-intense objects and don’t dispose of them themselves as they should and punishing the users who work with these types of objects correctly.