title: Calling Async synchronously, 'marshalled for a different thread' message
body: <p>I have a Windows 8 store app in XAML. I have an Image control that binds to a property, but because the URL I want to display requires authentication, I have to create a webresponse and generate the bitmap that way instead of just providing a URL to my image control. </p>
  
  <p>Problem is, the memorystream operations are async, and properties on an object have to be sync, not async. So I have a pretty simple setup:</p>
  
  <pre><code>public ImageSource ImageSource
  {
      get { return Task.Run(() =&gt; BitmapImageUtils.ToImage(this.Upload.ThumbFile)).Result; }
  </code></pre>
  
  <p>and the Image control has the ImageSource property as its binding. Problem is, I'm receiving the below exception. there's multiple Image controls in a ListView and they're all binding in this way, and my guess is that the UI thread that invokes this somehow hands off control to a thread then tries to come back somehow. I'm a little new to this.</p>
  
  <p>The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))</p>
  
  <p>Any help is appreciated.</p>
  
  <p>--- EDIT
  ToImage Method</p>
  
  <pre><code>public static async Task&lt;BitmapImage&gt; ToImage(byte[] byteArray)
      {
          var bitmapImage = new BitmapImage();
  
          var stream = new InMemoryRandomAccessStream();
          await stream.WriteAsync(byteArray.AsBuffer());
          stream.Seek(0);
  
          await bitmapImage.SetSourceAsync(stream);
          return bitmapImage;
      }
  </code></pre>
  
  <p>Exception (Note the exception is an inner exception of an aggregate exception, which I believe is pretty standard for async/await exceptions</p>
  
  <pre><code>at Windows.UI.Xaml.Media.Imaging.BitmapImage..ctor()
  at Campfire.Utils.BitmapImageUtils.&lt;ToImage&gt;d__0.MoveNext()
  </code></pre>