No Main() in WPF?

The Main() method is created automatically.
If you want to provide your own you have to (tested in VS2013, VS2017 and VS2019):

  • Right-click App.xaml in the solution explorer, select Properties
  • Change ‘Build Action’ to ‘Page’ (initial value is ‘ApplicationDefinition’)

Then just add a Main() method to App.xaml.cs. It could be like this:

[STAThread]
public static void Main()
{
    var application = new App();
    application.InitializeComponent();
    application.Run();
}

Leave a Comment