I am trying to debug an OutOfMemoryException that occurs when creating a fairly large ZIP file using System.IO.Packaging.ZipPackage .
The code iterates through a large list of objects, doing the following for each object:
- Serialization of object data to a temporary file.
- Create a
PackagePart for the file. - Copy from
System.IO.Stream source to another:- Source Stream:
FileStream - Target stream:
PackagePart::GetStream() => MS.Internal.IO.Zip.ZipIOModeEnforcingStream
Finally, it calls Package::Close() , which saves the file.
The problem I'm experiencing is that for a particularly large list of objects, I see an OutOfMemoryException (the x86 process reaches a size of about 1.2 GB).
I was thinking about dividing the object data into pieces, so I only process a smaller amount per loop (i.e. steps 1-3 above). The idea is that I will create n ZIP files in a temporary directory and then find a way to combine them into one archive.
Is this possible with System.IO.Packaging ? What would I like to use to combine parts?
Or is there a better way to fix this?
source share