title: Why does this silverlight code get a "catastrophic failure" when reading a BitmapImage out of IsolatedStorage?
body: <p>In a <strong>Silverlight</strong> app, I save a <strong>Bitmap</strong> like this:</p>
  
  <pre><code>public static void SaveBitmapImageToIsolatedStorageFile(OpenReadCompletedEventArgs e, string fileName)
  {
      using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
      {
          using (IsolatedStorageFileStream isfs = new IsolatedStorageFileStream(fileName, FileMode.Create, isf))
          {
              Int64 imgLen = (Int64)e.Result.Length;
              byte[] b = new byte[imgLen];
              e.Result.Read(b, 0, b.Length);
              isfs.Write(b, 0, b.Length);
              isfs.Flush();
              isfs.Close();
              isf.Dispose();
          }
      }
  }
  </code></pre>
  
  <p>and <strong>read</strong> it back out like this:</p>
  
  <pre><code>public static BitmapImage LoadBitmapImageFromIsolatedStorageFile(string fileName)
  {
      string text = String.Empty;
  
      using (IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication())
      {
          if (!isf.FileExists(fileName))
              return null;
  
          using (IsolatedStorageFile isoStore = IsolatedStorageFile.GetUserStoreForApplication())
          {
              using (IsolatedStorageFileStream isoStream = isoStore.OpenFile(fileName, FileMode.Open))
              {
                  BitmapImage bitmapImage = new BitmapImage();
                  bitmapImage.SetSource(isoStream);
                  return bitmapImage; // "Catastrophic Failure: HRESULT: 0x8000FFFF (E_UNEXPECTED))"
              }
          }
      }
  }
  </code></pre>
  
  <p>but this always gives me a "<strong>Catastrophic Failure: HRESULT: 0x8000FFFF (E_UNEXPECTED))</strong>" error.</p>
  
  <p>I've seen this error before when I tried to read a <strong>png file</strong> off a server which was actually a <strong>text file</strong>, so I assume the Bitmap is not being saved correctly, I <a href="http://www.dotnetcurry.com/ShowArticle.aspx?ID=234" rel="nofollow noreferrer">got the code here</a>.</p>
  
  <p><strong>Can anyone see how the BitmapImage is not being saved correctly? Or why it would be giving me this error?</strong></p>
  
  <h1>Update:</h1>
  
  <p><strong>When the BitmapImage is created, I see that the array of bytes that gets written is 1876 bytes long and they are all 0. Why would that be?</strong></p>