ExecutionEngineException

I have created a WPF library with GOXAM controls in it and want to show a window from this library from a Winforms exe.

This needs an instance of trivial class that inherits from System.Windows.Application so the License can be embedded, I have done that. Now window brings up the diagram control without the watermark, but when this window is closed and user opens up another instance of the same window he gets an ExecutionEngineException.

Is there any other way of embedding the license like it used to be for GoDiagram via the .licx file or is there a way to get rid of the ExecutionEngineException.

I’m not familiar with this situation, but my first thought was to make sure that your Application-subclass is not constructed more than once.

I make an instance of Application subclass at the start of Winform exe and keep on holding the instance till exe closes. So in other words, I only make one instance

I just created a WinForms apps that just has a Button and an ElementHost. Clicking the button replaces the ElementHost’s Child with a new WPF UserControl that holds a Diagram.

Here’s the definition of the whole Form:

[code]namespace WindowsFormsApplication1 {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
new MyApp();
}

private void button1_Click(object sender, EventArgs e) {
  elementHost1.Child = new WpfControlLibrary1.UserControl1();
}

}

public class MyApp : System.Windows.Application {
public MyApp() {
// This is a runtime license key for Northwoods.GoWPF version 1.2 (or earlier)
// Put the following statement in your WindowsFormsApplication1 application constructor:
Northwoods.GoXam.Diagram.LicenseKey = “. . .”;
}
}
}[/code]
This does create the System.Windows.Application object in the Form constructor rather than in the Program.Main static method, but for this app the lifetime of the Form1 is the same as the lifetime of the whole app, so either way works.

The definition of the WPF UserControl doesn’t really matter, but for completeness, here it is:

<UserControl x:Class="WpfControlLibrary1.UserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:go="http://schemas.nwoods.com/GoXam"> <Grid> <go:Diagram x:Name="myDiagram" /> </Grid> </UserControl>

[code]namespace WpfControlLibrary1 {
///


/// Interaction logic for UserControl1.xaml
///

public partial class UserControl1 : UserControl {
public UserControl1() {
InitializeComponent();

  var model = new GraphLinksModel<String, String, String, UniversalLinkData>();
  model.NodesSource = new List<String>() { "a", "b", "c", "d", "e" };
  model.LinksSource = new List<UniversalLinkData>() {
    new UniversalLinkData("a", "b"),
    new UniversalLinkData("a", "c"),
    new UniversalLinkData("c", "d"),
    new UniversalLinkData("c", "e")
  };
  myDiagram.Model = model;
}

}
}[/code]
Everything works the way you would expect.

I suspect that ExecutionEngineException is due to some problem other than licensing, perhaps with resources.

I see, problem is with .NET framework itself and not your licensing but there could be a limitation with this model of licensing (not 100% sure about the nitty gritty of interoperability) that you can not show a WPF window from a WPF library. I was calling ShowDiagram method from WPF library and on second call to this method I got the ExecutionEngineException

public void ShowDiagram(IntPtr OwnerHandle)

{

MainWindow window = new MainWindow();

WindowInteropHelper helper = new WindowInteropHelper(window);

helper.Owner = OwnerHandle;

window.Show();

}

Now I have changed the window to a usercontrol and host it in a winform using elementhost and everything seem to be working fine.

Thanks for your help Walter.



Updated on 2nd -Feb-2011

--------------------------------------------------------

Another workaround to this problem is that you set ShutdownMode to OnExplicitShutdown

<br />System.Windows.Application app = new App(); <br />app.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown; <br />

that way you can call WPF window directly without it throwing the ExecutionEngineException