locked
Read XML from Azure CDN Marshalled error

    Question

  • I would like to load an XML file stored in Azure CDN in a Windows 8.1 App. This code throws Marshaling error:The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))

           public async Task<XDocument> LoadXmlFromCDNAsync()

            {
      var url = new Uri("http://azXXXXXX.vo.msecnd.net/cdn/Data.xml");
                var handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip };
                var client = new HttpClient(handler);
                XDocument doc = new XDocument();
                using (var stream = await client.GetStreamAsync(url))
                {
                    doc = XDocument.Load(stream);
                }
                return doc;
            }

    Thanks.


    FS

    Tuesday, February 10, 2015 5:25 PM

Answers

All replies

  • Hi,

     I accidentally  move your thread to offtopic. I am very sorry for that. I will ask someone move your thread back to windows store app forum.

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    Wednesday, February 11, 2015 6:06 AM
  • Hi,

    I test your codes. And the result below:

    I can successfully load the XML file. I think there is no problem in the codes which you used to load an XML file.

    And as the error says, the problem is the thread on which the call occurs: the app cannot manipulate UI elements from non-UI threads.  That error usually means you are calling something that requires the UI thread from a different thread. You can call Dispatcher.RunAsync to marshall a task back to the UI thread.

    See http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.core.coredispatcher.runasync.aspx

    And see the thread below:

    https://social.msdn.microsoft.com/Forums/en-US/f1fe027f-2c6c-4a22-9418-566fcf67cebe/the-application-called-an-interface-that-was-marshalled-for-a-different-thread?forum=winappswithcsharp

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place. <br/> Click <a href="http://support.microsoft.com/common/survey.aspx?showpage=1&scid=sw%3Ben%3B3559&theme=tech"> HERE</a> to participate the survey.

    • Marked as answer by Frank14303 Wednesday, February 11, 2015 1:10 PM
    Wednesday, February 11, 2015 6:24 AM