The exception is thrown on the following line: [https://github.com/tonyqus/npoi/blob/master/ooxml/openxml4Net/Util/ZipInputStreamZipEntrySource.cs#L134](https://github.com/tonyqus/npoi/blob/master/ooxml/openxml4Net/Util/ZipInputStreamZipEntrySource.cs#L134)
I have done a little research and discovered that the issue is that each process has memory limitations and this is often hit when converting a large stream to an array of bytes. This is because memory is fragmented and there is no way to map it back or ensure that other blocks of memory are available. I believe this can possibly be solved by either passing references of the a stream or temporarily writing the decompressed data to disk. I have not tried either suggested solution.
[http://blogs.msdn.com/b/ericlippert/archive/2009/06/08/out-of-memory-does-not-refer-to-physical-memory.aspx](http://blogs.msdn.com/b/ericlippert/archive/2009/06/08/out-of-memory-does-not-refer-to-physical-memory.aspx)
Comments: ** Comment from web user: olibara **
Hello I have the same issue but there is a bit more information about it, it seems that there is really a bug in memory management within NPOI !
Test : I first get the problem during workbook.write of a big worksheet of 158.000 rows and 30 column
Then I try to simplify the content by simply fill the worksheet with 158.000 x 30 EMPTY rows / cell
```
foreach (DataRow row in sourceTable.Rows)
{
IRow dataRow = sheet.CreateRow(iRow);
iRow = sheet.LastRowNum + 1;
foreach (DataColumn column in sourceTable.Columns)
{
int I = column.Ordinal;
dataRow.CreateCell(I);
continue;
}
}
```
after that workbook.write worked
But then I create a new workbook (without closing application) and run the same creation process
But then the workbook.write failed
So I'm suspecting that NPOI have an internal memory management bug
N.B. : this is my Write procedure (I also keep care to clear the Worbook even it will not be used anymore and should be disposed
```
using (FileStream fStream = new FileStream(fileName, FileMode.Create))
{
workbook.Write(fStream);
fStream.Close();
workbook.Clear();
}
```