This project has moved and is read-only. For the latest updates, please go here.

Not Properly Disposing?

Sep 15, 2014 at 8:53 PM
I recently upgraded some export code that I'd done not that long ago to using the 4.0 Beta, so that I could try it out. When I did run it (with code that had worked perfectly with the regular version) it spat out an Excel file of size 0KB, and which, when I opened it up, said that the file was either in the wrong format or unreadable.

After poking and prodding it for a while I finally figured out what was wrong. I had done the following for my export:
using (var db = new DbContext())
{
  using (var package = new ExcelPackage(stream))
  {
     //Some export of data found in the Context
  }
}
But when I split out all of the DB calls into its own using, ala:
using (var db = new DbContext())
{
  //all my needed db calls
}

using (var package = new ExcelPackage(stream))
{
   //Some export of data found in the Context
}
Then it started working again. Has anyone else encountered this in the Beta? Does anyone fully know why this happened? Is it just not able to fully dispose the ExcelPackage when it's in another using statement anymore?