Quantcast
Channel: EPPlus Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 2262

Edited Unassigned: InvalidOperationException when saving package [15401]

$
0
0
I am trying to import a worksheet that references a vmlDrawing part using code similar to this:

using (ExcelPackage xls = new ExcelPackage())
{
using (ExcelPackage source = new ExcelPackage(new FileInfo("source.xlsx")))
{
xls.Workbook.Worksheets.Add("Imported", source.Workbook.Worksheets[1]);
}
xls.SaveAs(new FileInfo("tst.xlsx"));
}

The source.xlsm file has a vmlDrawing xml part and the first sheet references that part. When saving 'tst.xlsx' I get an `InvalidOperationException` with message: 'Cannot access a closed Stream.'

The issue seems to be caused by the `using` block in the `CopyVmlDrawing(ExcelWorksheet origSheet, ExcelWorksheet newSheet)` in __ExcelWorksheets.cs__ file where the stream is disposed after the `using` block.

using (var streamDrawing = new StreamWriter(part.GetStream(FileMode.Create, FileAccess.Write)))
{
streamDrawing.Write(xml);
streamDrawing.Flush();
}

Then when `WriteZip(ZipOutputStream os)` in __ZipPackagePart.cs__ is invoked. The line `b = GetStream().ToArray();` tries to access the closed stream.

Viewing all articles
Browse latest Browse all 2262

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>