title: How can I run a WPF application in a new AppDomain? ExecuteAssembly fails
body: <p>I'm trying to launch a WPF application from a Console application, using Application Domains,
  but when I do, I receive unexpected errors.</p>
  
  <p>Running the WPF application standalone, works.</p>
  
  <p>This code works, too:</p>
  
  <pre><code>var baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
  var path = string.Format("{0}AddressbookDesktop.exe", baseDirectory);
  var processInfo = new ProcessStartInfo(path, "");
  Process.Start(processInfo);    
  </code></pre>
  
  <p>But this code fails with the error below. The error appears to be in the constructor, which is empty:</p>
  
  <pre><code>var addressbookDomain = AppDomain.CreateDomain("addressbookDomain");
  addressbookDomain.ExecuteAssembly("AddressbookDesktop.exe");
  </code></pre>
  
  <p>Stack trace:</p>
  
  <pre><code>System.Windows.Markup.XamlParseException: Cannot create instance of 
  'AddressbookMainWindow' defined in assembly 'AddressbookDesktop, Version=1.0.0.0, 
  Culture=neutral, PublicKeyToken=null'. Exception has been thrown
  by the target of an invocation. Error in markup file 'AddressbookMainWindow.xaml' Line     1 Position 9.
  ---&gt; System.Reflection.TargetInvocationException: Exception has been thrown by the
  target of an invocation. ---&gt; System.InvalidOperationException: The calling thread must 
  be STA, because many UI components require this.
  
  at System.Windows.Input.InputManager..ctor()
  at System.Windows.Input.InputManager.GetCurrentInputManagerImpl()
  at System.Windows.Input.InputManager.get_Current()
  at System.Windows.Input.KeyboardNavigation..ctor()
  at System.Windows.FrameworkElement.FrameworkServices..ctor()
  at System.Windows.FrameworkElement.EnsureFrameworkServices()
  at System.Windows.FrameworkElement..ctor()
  at System.Windows.Controls.Control..ctor()
  at System.Windows.Controls.ContentControl..ctor()
  at System.Windows.Window..ctor()
  at XX.YY.AddressbookDesktop.AddressbookMainWindow..ctor() in      C:\.....\AddressBookDesktop\AddressbookMainWindow.xaml.cs:line 15
  --- End of inner exception stack trace ---
  </code></pre>
  
  <p>I guess I'm doing something wrong, but can't understand what it is.
  Thanks for any help.</p>