private static void GetDeploymentBinaries( DirectoryInfo targetAssemblyDirectory, out Stream binariesStream, out Stream hashesStream) { ZipArchive zipArchive = null; StreamWriter hashesWriter = null; try { binariesStream = new MemoryStream(); zipArchive = new ZipArchive(binariesStream, ZipArchiveMode.Create, leaveOpen: true); hashesStream = new MemoryStream(); hashesWriter = new StreamWriter(hashesStream, Encoding.UTF8, 1024, leaveOpen: true); ZipUtility.ZipRecursive( targetAssemblyDirectory.FullName, targetAssemblyDirectory, zipArchive, hashesWriter, m_HashName); hashesWriter.Flush(); hashesStream.Seek(0, SeekOrigin.Begin); // rewind the stream for the caller } finally { zipArchive.SafeDispose(); hashesWriter.SafeDispose(); } // for some reason zipArchive isn't fully written to the stream until it is disposed // (tried calling Flush on binariesStream and that didn't work) // rewind the stream for the caller after the Dispose binariesStream.Seek(0, SeekOrigin.Begin); }