Bug 2865 - MemoryStream object is disposed when it should not have been
Summary: MemoryStream object is disposed when it should not have been
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2012-01-12 11:32 UTC by Alex Wielhouwer
Modified: 2012-01-13 21:34 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Alex Wielhouwer 2012-01-12 11:32:06 UTC
I have an ASP.NET page that creates an excel file using GemBox from a data table
           ExcelFile ef = new ExcelFile();
            ExcelWorksheet ws = ef.Worksheets.Add("DataSheet");
            ws.InsertDataTable(log, "A1", true);
            Response.ContentType = "application/vnd.openxmlformats";
            Response.AddHeader("Content-Disposition", "attachment; filename=oncue24"+Request["action"].ToString().Trim()+".xlsx");
                MemoryStream ms = new MemoryStream();
                ms.WriteTo(Response.OutputStream); // Object disposed error occurs here
                ms = null;

It works under Microsoft ASP.NET, but under MONO the MemoryStream seems to have been disposed after the SaveXlsx. I have seen reference to an issue in
System.IO.Packaging in MONO (http://mono.1490590.n4.nabble.com/creating-excel-files-td3315324.html#a3319632). I have confirmed with gemBox tech support that they are using the IO.Packaging system and are closing the package.

How is it sensible that we want to create a stream using packaging and then have that stream unusable?

In the referenced link there is a quoted section from a developer:
> On Mon, Feb 28, 2011 at 3:26 PM, Rafael Teixeira<[hidden email]>  wrote: 
>> That is the documented (expected) behavior of Close: 
>> "Saves and closes the package plus all underlying part streams." 
>> See 
>> http://msdn.microsoft.com/en-us/library/system.io.packaging.package.close.aspx

I would suggest the developer is failing to recognize the meaning of the word underlying. Any Object passed into the Packaging class is an overlying stream, as its creating is not under the control of the Packaging class, and thus should remain open.
Comment 1 Miguel de Icaza [MSFT] 2012-01-13 19:13:31 UTC
This was fixed in recent versions of Mono.

Please upgrade your Mono.    

It took me a while to track down the fix, if you need to reopen, please provide a test case showing the broken behavior.
Comment 2 Alex Wielhouwer 2012-01-13 21:34:17 UTC
Thank you. I did't realize till now the Ubuntu hasn't incorporated the latest version in the repositories (still experimental). Guess I'll have to work around it for now.