I am using aspose.cell 17.5.0.0 and I found that Workbook.Dipose() does not close the Stream it use:
var fs = File.Open(“some file path”, FileMode.Open);
using (var wb = new Workbook(fs))
{
}
Console.WriteLine(fs.Length); // expect ObjectDisposedException but no exception thrown
Is it a bug? if no, then what is the point of using workbook with using statement?
Hi,
Well, you got to close or dispose the stream by yourself, see the sample code for your reference:
e.g
Sample code:
var fs = File.Open(“e:\test2\Book1.xlsx”,
FileMode.Open);
using (var wb = new Workbook(fs))
{
}
fs.Dispose();
//Or close it
//fs.Close();
Console.WriteLine(fs.Length); // expect ObjectDisposedException but no exception thrown
Thank you.
Thanks.
But shouldn't a disposable class take the responsibility for disposing resources it holds? If Workbook doesn't do so, maybe it is worth mentioning on the document.
And could you please tell me is there any good reason I should use Workbook with using statement
Thanks, I see your point but I think it is dangerous if you don’t tell user you are not going to dispose the stream. For example, if one follows the advice of https://msdn.microsoft.com/en-us/library/ms182334.aspx
, he will get into trouble with resources leaking.
Hi,
Thanks for your sharing your concerns.
We will discuss with our product team and may update/enhance the description of Workbook.Dispose() method in the help file of Aspose.Cells for .NET API Reference guide (if possible).
Thank you.