title: The stream was not openned for reading
body: <p>I am downloading a PowerPoint file from Cloud. To restrict the multiple call for downloading the file, I am caching it using <code>MemoryCache</code>. The below code runs fine for first run, but after the first run it throws an exception: </p>
  
  <blockquote>
    <p>"The stream was not opened for reading."</p>
  </blockquote>
  
  <p>Below is the code I am using:</p>
  
  <pre><code>var cache = MemoryCache.Default;
  var memoryStream = new MemoryStream();
  if(cache.contains(key)) {
      memoryStream = (MemoryStream)cache.Get(key);
  } else {
      var file = getFile();
      cache.Add(key, file);
      memoryStream = (MemoryStream)cache.Get(key);
  }
  
  using(memoryStream) {
      Open file and do manupulation then save the file in cloud.
  }
  </code></pre>
  
  <p>Updated code:</p>
  
  <pre><code>var cache = MemoryCache.Default;
  byte[] data = (byte[])cache.Get(key);
  if(data == null)
  {
      data_stream = getData(); // get memorystream
      cache.Add(key, data_stream.ToArray(), new CacheItemPolicy());
      data = (byte[])cache.Get(key);
  }
  
  using(Stream outputStream = new MemoryStream(decktemplate)) {
      Open file and do manupulation then save the file in cloud.
  }
  </code></pre>
  
  <p>still getting the following error: "Arithmetic operation resulted in an overflow."</p>
  
  <p>Following is the stacktree:</p>
  
  <pre><code>   at MS.Internal.IO.Zip.ZipIOExtraField.ParseRecord(BinaryReader reader, ZipIOZip64ExtraFieldUsage zip64extraFieldUsage, UInt16 expectedExtraFieldSize)
     at MS.Internal.IO.Zip.ZipIOCentralDirectoryFileHeader.ParseRecord(BinaryReader reader, Encoding encoding)
     at MS.Internal.IO.Zip.ZipIOCentralDirectoryBlock.ParseRecord(BinaryReader reader, Int64 centralDirectoryOffset, Int32 centralDirectoryCount, Int64 expectedCentralDirectorySize)
     at MS.Internal.IO.Zip.ZipIOCentralDirectoryBlock.SeekableLoad(ZipIOBlockManager blockManager)
     at MS.Internal.IO.Zip.ZipIOBlockManager.get_CentralDirectoryBlock()
     at MS.Internal.IO.Zip.ZipArchive.GetFiles()
     at System.IO.Packaging.ZipPackage.ContentTypeHelper..ctor(ZipArchive zipArchive, IgnoredItemHelper ignoredItemHelper)
     at System.IO.Packaging.ZipPackage..ctor(Stream s, FileMode mode, FileAccess access, Boolean streaming)
     at System.IO.Packaging.Package.Open(Stream stream, FileMode packageMode, FileAccess packageAccess, Boolean streaming)
     at DocumentFormat.OpenXml.Packaging.OpenXmlPackage.OpenCore(Stream stream, Boolean readWriteMode)
     at DocumentFormat.OpenXml.Packaging.PresentationDocument.Open(Stream stream, Boolean isEditable, OpenSettings openSettings)
     at DocumentFormat.OpenXml.Packaging.PresentationDocument.Open(Stream stream, Boolean isEditable)
  </code></pre>