wpflinqpadfreezable

LinqPad WPF window InvalidOperationException on second execution


I try to open a WPF window containing my WPF user control on LinaPad.

var w = new System.Windows.Window() { Content = myControl };
w.ShowDialog();

This code works only for the first time execution after opening a query tab. If I execute the code again, then it throw InvalidOperationException saying

Cannot use a DependencyObject that belongs to a different thread than its parent Freezable

Is there any difference between the first time execution environment and the later execution environment in LinqPad?


Solution

  • I'm guessing you've created myControl on another thread.

    The following works without error for me:

    var w = new System.Windows.Window() { Content = "foo" };
    w.ShowDialog();
    

    Another solution is simply to dump myControl:

    myControl.Dump();
    

    LINQPad will then render it in its output window.