Release Workbook resources in .NET

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

Hi,


Well, surely, it is not our component’s responsibility to close those resources that are opened by you/user in his code. In your sample code, the file stream is created by your code, so we should not close it. We think a component (library) should only control the life of objects generated by itself and not others. For a user’s given stream, it might be possible that the needs to process it further after we have used it (loading data from it or writing data into it, etc.), so, closing the streams in our component is not viable option by any means.

Thank you.

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.