Note that there are some explanatory texts on larger screens.

plurals
  1. POLaunching a CustomAction UI written with WPF from a WIX installer: Fail on STAThread issue
    primarykey
    data
    text
    <p>My WIX installer launches an immediate custom action. The custom action starts a WPF dialog prompting the user for a BD connection parameters (I basically wrote the 'new connection' DB prompter dialog in WPF, to get me a connection string that the custom action can inject in the installed application's configuration file). The WIX code is fairly simple to figure out, and I know I execute the custom action just fine - I put there a MessageBox and a MmsiBreak on the call to my custom action method. I get there without a problem. When the custom action instantiates my WPF dialog window, I get an InvaliOperationException: "The calling thread must be STA, because many UI components require this". </p> <p>The same code runs fine when I put it in a standard WPF application, because VisualStudio generates boiler plate code with Main() that has a STAThreadAttribute on it. I can't tack that attribute on the msiexec caller, and if I try to set the thread apartment state in my custom action, it fails:</p> <pre><code>Thread.CurrentThread.SetApartmentState(ApartmentState.STA); </code></pre> <p>Is not supposed to work for framework past 2.0.</p> <p>Is there any way to do what I'm trying to do here? I'd appreciate some pointers.</p> <hr> <h2>EDIT</h2> <p>I even tried to run the dialog in its own thread, e.g. the code is like this:</p> <pre><code>// Static class members static ManualResetEvent _done = new ManualResetEvent(false); static ActionResult _caResult; static Session _session; static Thread _worker; [CustomAction] static public ActionResult PromptForDB(Session session) { _session = session; _worker = new Thread(WorkerThread); _worker.Start(); _done.WaitOne(); return _caResult; } [STAThread] static void WorkerThread() { try { Prompter wnd = new Prompter(); if (!(bool)wnd.ShowDialog()) { _caResult = ActionResult.SkipRemainingActions; } else { // Harvest our properties (omitted from this post) _caResult = ActionResult.Success; } catch (Exception ex) { _caResult = ActionResult.Failure; _session.Log("Error: " + ex.Message); } finally { _done.Set(); } } </code></pre> <p>That does not work either.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload