title: Access is denied when running an async function twice that writes to local storage
body: <p>I have a C# project with a service reference against a web service.</p>
  
  <p>I have the following code, first to trigger a method at the service request:</p>
  
  <pre><code> private void Button_Click(object sender, RoutedEventArgs e)
   {
       App.service.getFileCompleted += service_getFileCompleted;
       App.service.getFileAsync(App.user, App.document);
   }
  </code></pre>
  
  <p>And the <code>service_getFileCompleted</code> is supposed to retrieve a <code>byte[]</code>, put it into a file and then open that file with the default application:</p>
  
  <pre><code> async void service_getFileCompleted(object sender, BackendReference.getFileCompletedEventArgs e)
   {
              string tmp = "temp." + e.Result.type;
  
              StorageFolder local = Windows.Storage.ApplicationData.Current.LocalFolder;
              StorageFile localFile = await local.CreateFileAsync(tmp, CreationCollisionOption.ReplaceExisting);
  
              using (Stream writeStream = await localFile.OpenStreamForWriteAsync())
              {
                  writeStream.Seek(0, SeekOrigin.End);
                  await writeStream.WriteAsync(e.Result.fileData, 0, e.Result.fileData.Length);
              }
  
              await Windows.System.Launcher.LaunchFileAsync(localFile);
  
          }
   }
  </code></pre>
  
  <p>First time the apps starts, and the button is triggered it works like a charm. However, when pressing the button the second time the row </p>
  
  <pre><code>Stream writeStream = await localFile.OpenStreamForWriteAsync()
  </code></pre>
  
  <p>casts an <code>System.UnauthorizedAccessException</code>.</p>
  
  <p>More exactly:</p>
  
  <blockquote>
    <p>System.UnauthorizedAccessException: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))<br>
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)<br>
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)<br>
    at System.IO.WindowsRuntimeStorageExtensions.d__5.MoveNext()  </p>
    
    <p>--- End of stack trace from previous location where exception was thrown ---</p>
    
    <p>at System.IO.WindowsRuntimeStorageExtensions.d__5.MoveNext()  </p>
    
    <p>--- End of stack trace from previous location where exception was thrown ---</p>
    
    <p>at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)<br>
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)<br>
    at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()<br>
    at archive.DocumentDetail.d__0.MoveNext()}  System.Exception {System.UnauthorizedAccessException}  </p>
  </blockquote>
  
  <p>Why is this so?</p>
  
  <p>Thanks</p>