title: Running UrhoSharp in a UWP app as new view
body: <p>I'm interested in building a UWP app that, when launched, has a default 2D XAML type view, but can switch to a secondary 3D UrhoSharp view (incidentally, this is to be run on HoloLens). I'm new to UrhoSharp but I'm able to follow some online tutorials that create a 3D UWP UrhoSharp application by creating a new UWP app in Visual Studio, deleting the "App.xaml" and "MainPage.Xaml" classes and then defining a new UrhoSharp entry point by adding the following:</p>
  
  <pre><code>using Urho;
  
  public static class Program
  {
      [MTAThread]
      static void Main() =&gt; CoreApplication.Run(new UrhoAppViewSource&lt;MixedRealityApplication&gt;());
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>using Urho;
  using Urho.SharpReality;
  
  internal class MixedRealityApplication : StereoApplication
  {
      public MixedRealityApplication(ApplicationOptions options) : base(options)
      {
          // Do some initialization.
      }
  
      protected override void Start()
      {
          // Start drawing some 3D stuff
      {
  }
  </code></pre>
  
  <p>The above works and I'm able to see my 3D objects. Now I wish to create a UWP application that starts with its default view as a standard 2D XAML window but then be able to switch to a 3D UrhoSharp view when clicking a button. I found the following thread where the author has done exactly that:</p>
  
  <p><a href="https://forums.xamarin.com/discussion/98907/right-way-to-run-urhosharp-as-part-of-2d-uwp-on-hololens" rel="nofollow noreferrer">https://forums.xamarin.com/discussion/98907/right-way-to-run-urhosharp-as-part-of-2d-uwp-on-hololens</a></p>
  
  <p>However, the code example is very sparse (1 or 2 lines) and I can't get anywhere. I've tried using the (unmodified) "MixedRealityApplication" class in the code above in the way used by the author:</p>
  
  <pre><code>Using Windows.ApplicationMode.Core;
  using Urho;
  
  private void Button_Click)object sender, RoutedEventArgs e)
  {
      CoreApplicationView urho3DView = CoreApplication.CreateNewView(new UrhoAppViewSource&lt;MixedRealityApplication&gt;());
      ...etc...
  }
  </code></pre>
  
  <p>The above throws the following exception when trying to instantiate "urho3DView": "System.Runtime.InteropServices.COMException: 'A method was called at an unexpected time.'"</p>
  
  <p>I not sure what else to try, and the fact that it seems possible according to the linked post is tantalizing. Does anyone have any idea as to how to go about this? If only the author had shown what "HelloWorldApplication" looks like in his/her code.</p>