Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# WinRT component fails in UserControl constructor calling from WinJS

We are building a WinRT application with JavaScript (WinJS) that accesses REST/JSON web services via C# WinRT Component library. In the component library we have a Logon control (much like WebAuthenticationBroker) that allowes us to use ACS logon with our REST services.

Application Layers:

  • Client (JS)
  • WinRT component dll (C#)
  • C# ClassLibrary dll (C#)
  • UserControl (Xaml/C#, contains WebView)

The problem: When trying to create the logon control, the WinRT throws "HRESULT: 0x8001010E (RPC_E_WRONG_THREAD)" exception (when entering the UserControl's constructor) even if I call it via Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher (recommended in MSDN article I found about WinJS/C++ component).

If I call it from a Xaml/C# client, the code works with or without the Windows.UI.Core.CoreWindow.GetForCurrentThread().Dispatcher.RunAsync().

I've tried to google this and also read all the UserControl, Dispatcher and WinJS documentation but I have not found anything relevant. Is this a known problem and could someone suggest a workaround?

Since I'm a first time poster, please be gentle :-) Any help is extremely welcome!

like image 327
PetriL Avatar asked Jan 17 '13 12:01

PetriL


1 Answers

Xaml-based WinRT controls cannot be used in Javascript-based WinRT projects. You can use any WinRT class library, but not Xaml controls inside them.

If you still want to combine HTML-Javascript with Xaml, I would recommend creating a Xaml-based project, and wrapping your HTML UI in a WebView control.

like image 181
yms Avatar answered Sep 30 '22 00:09

yms