I got following setup:
WPF_Application.exe
and
a DLL that contains a WinForms Window and an WPF Window.
The \'WPF_Application.exe\' calls th
Make sure you only have one Application defined in XAML.
Visual studio creates an App.xaml
when making a new WPF solution, if you have created a new .xaml file with the <Application></Application>
tag, this will cause this error and the solution will build but fail at runtime.
Delete the duplicate application and use Window
or UserControl
to have multiple windows.
System.Windows.Application is a singleton: its constructor must only be invoked once (including App.xaml de-xamlization), or exception is thrown.
I'm affraid there is not much you can do about it, except maybe check if Application.Current is set before starting your second application, and somewhat use that instance to load it.
Or you can create another AppDomain, and use it to launch the second application.
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;