title: Access is Denied when Saving a Object in in local storage Windows 8 Metro App
body: <p>I'm attempting to store a List (where Show is my class that implements IXmlSerializable) to the local isolated storage. I'm using the code from this page:
  <a href="http://metrostoragehelper.codeplex.com/" rel="nofollow">http://metrostoragehelper.codeplex.com/</a> 
  I've implemented the change suggested in the Issues section.
  I am using the following code to add a Show object when it is clicked from an item list. </p>
  
  <pre><code>private async void addShowButton_Click_1(object sender, RoutedEventArgs e)
      {
          var isoStorage = new StorageHelper&lt;List&lt;Show&gt;&gt;(StorageType.Local);
  
          List&lt;Show&gt; currentShows = await isoStorage.LoadASync("myShowsEx");
          if(currentShows == null) {
              currentShows = new List&lt;Show&gt;();
          }
  
          currentShows.Add(currentShow);
  
          isoStorage.SaveASync(currentShows, "myShowsEx");
  
  
          //Read it back, for debugging to check if it has been added properly. 
          List&lt;Show&gt; currentShowsRB = await isoStorage.LoadASync("myShowsEx"); //Exception here
  
      }
  </code></pre>
  
  <p>The first show is added perfectly fine and it shows up in the currentShowsRB List. When a second item is clicked and the method above invoked an exception occurs on the last LoadAsync call: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))
  How can I get around this to access the local data store for multiple calls?</p>
  
  <p>Below is also the relevant code from the StorageHelper:</p>
  
  <pre><code>public async void SaveASync(T Obj, string FileName)
      {
  
          FileName = FileName + ".xml";
          try
          {
              if (Obj != null)
              {
                  StorageFile file = null;
                  StorageFolder folder = GetFolder(storageType);
                  file = await folder.CreateFileAsync(FileName, CreationCollisionOption.ReplaceExisting);
  
                  using (var writeStream = await file.OpenAsync(FileAccessMode.ReadWrite))
                  {
                      Stream outStream = Task.Run(() =&gt; writeStream.AsStreamForWrite()).Result;
                      serializer.Serialize(outStream, Obj);
                      //writeStream.Dispose(); //Added and we get UnauthorizedAccessException
                      // outStream.Dispose(); //Added ObjectDisposedException caught in catch statement below
                  }
              }
          }
          catch (Exception)
          {
              throw;
          }
      }
      public async Task&lt;T&gt; LoadASync(string FileName)
      {
          FileName = FileName + ".xml";
          try
          {
              StorageFile file = null;
              StorageFolder folder = GetFolder(storageType);
              file = await folder.GetFileAsync(FileName);
              using (var readStream = await file.OpenAsync(FileAccessMode.Read))
              {
                  Stream inStream = Task.Run(() =&gt; readStream.AsStreamForRead()).Result;
                  inStream.Position = 0;
                  return (T)serializer.Deserialize(inStream);
              }
          }
          catch (FileNotFoundException)
          {
              //file not existing is perfectly valid so simply return the default 
              return default(T);
              //throw;
          }
          catch (Exception)
          {
              //Unable to load contents of file
              throw;
          }
      }
  </code></pre>
  
  <p>The writeStream.Dispose() line I added in, but even when this is included I get the same error message of Access is Denied. If I also include the outStream.Dispose() line then I get a ObjectDisposedException being caught in the catch statement right below. Is there something else I should be doing? </p>