Question System.ExecutionEngineException while loading WPF window from Windows Form

I found some rather strange behavior...

Here is how to replicate the problem:

  1. Create a WPF Application Project.
  2. Remove the StartupUri from the App.xaml file.
  3. Add a Startup Event Handler to the App with signature "private void Application_Startup(object sender, StartupEventArgs e)"
  4. Now, add a Form to the project (right click and select add new item).
  5. in the Application_Startup method, create the form object and show it like Form1 f1 = new Form1(); f1.ShowDialog();
  6. On the actual Form1, add a button to the designer, and add a click event handler to the button.
  7. Add a new WPF window to your project, Window1.
  8. In the Form1's button click event handler created in step 6, add the lines of code to create display the WPF window: Window1 w1 = new Window1(); w1.Show();
  9. Run the project and click the button on the winform to show the WPF window... works fine so far.
    1. Close the WPF window and click the winform's button again. This time you should get the exception.

So, essentially what I do is create a WPF application that displays a winform. Then, the winform displays a WPF Window.

The first time the WPF window is displayed, everything works fine. If it is closed, and then re-opened, I get the exception! I can also open up multiple WPF windows by clicking the button multiple times. Once the last one is closed, however, I can never open another one again without the exception...

I have also tried the various tips suggested at but those don't help.

Why is this happening?


The default Wpf applicationshutdown behavior (specified on the "Application" tab in project properties in VS or using the ShutdownMode attribute in Application.Xaml) is "On Last Window Close". This means that when you close the Wpf window you create, Wpf shuts down the application framework so any subsequent window creations will throw an exception.

You can avoid this problem by setting the Shutdown mode to "On explicit shutdown" ("OnExplicitShutdown" in Xaml). You will then need to manually call Application.Current.Shutdown explicitly when you want the app to terminate (e.g. when the winforms form is closed).

Need Your Help

Fetch ip address of pc on android emulator through code android

android android-emulator ip

I want to get the ip address of my pc in android emulator through code....or tell me to achive ip address of all devices connected in a lan to identify each one uniquely .......please help me to so...

Public resources, spark & conflict resources spark-view-engine

Using this to generate my resources. Problem is, spark dies when tries to generate dynamic views because there is app_globalresources.dll and myapp.dll somewhere there - deep into temp jungles.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.