Multiple WPF Applications in the Same AppDomain

I got the following setting:

WPF_Application.exe

and

A DLL that contains a WinForms window and a WPF window.

"WPF_Application.exe" calls the WinForms window from the DLL, and the WinForms window creates an instance of the WPF window in the DLL.

This throws the following exception:

Unable to create multiple instances of System.Windows.Application in the same AppDomain.

I tried different things, but could not figure out how to fix it.

+7
c # winforms wpf
source share
2 answers

I fixed it by specifying the wpf window application that gets called in the Application.Current window:

if (Application.Current == null) { MyApplication = new Application { ShutdownMode = ShutdownMode.OnExplicitShutdown }; } else MyApplication = Application.Current; 
+11
source share

System.Windows.Application is a singleton: its constructor must be called only once (including App.xaml de-xamlization) or an exception is thrown.

I’m afraid that you can’t do this, except maybe check if Application.Current is installed before launching the second application and use this instance to load it a little.

Or you can create another AppDomain and use it to launch a second application.

+3
source share

All Articles