Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple WPF applications in the same AppDomain

Tags:

c#

winforms

wpf

I got following setup:

WPF_Application.exe

and

a DLL that contains a WinForms Window and an WPF Window.

The 'WPF_Application.exe' calls the WinForms window from the DLL and the WinForms Window creates an instance of the WPF window in the DLL.

That creates following exception:

Cannot create more than one System.Windows.Application instance in the same AppDomain.

Tried different things, but couldn't figure out how to fix it.

like image 377
JayTee Avatar asked Feb 18 '15 14:02

JayTee


1 Answers

I fixed it by asigning the Application of the wpf window that is called to the Application.Current Window:

  if (Application.Current == null)
  {
       MyApplication = new Application
       {
          ShutdownMode = ShutdownMode.OnExplicitShutdown
       };
   }
   else
       MyApplication = Application.Current;
like image 60
JayTee Avatar answered Sep 20 '22 05:09

JayTee