Fix: Program does not contain a static ‘Main’ method suitable for an entry point

1 minute read

This does not require a detailed post and just requires a quick solution for the problem-

Understanding the problem... Why? When?

When you convert a Winform application into a WPF application -  In a Winform or a Console application, you need a static Main method that acts as an entry point to your executable.  In a WPF application, you do not require any such static class to be present at the compile time.  You need an App.xaml file that appears something like this

[sourcecode language='xml']



[/sourcecode]

Here StartupUri represents the first/launch WPF Window or a Page and the App.xaml.cs is very short and simple

[sourcecode language='csharp']
using System.Windows;

namespace MyWPFApplication
{
///

/// Interaction logic for App.xaml
///

public partial class App : Application
{

}
}
[/sourcecode]

When you migrate a Winform application to WPF application, you can add this file explicitly to your project to get started. But when you would compile, you will find a compilation issue

Program does not contain a static 'Main' method suitable for an entry point

So the compiler treats App.xaml just like any other WPF page instead of a special class which we call it as ApplicationDefinition class.

What is the fix?

 

Check the properties of App.xaml. Change the Build Action to ApplicationDefinition and re-compile.

This also means, you can have any XAML file to be your ApplicationDefinition file.  But it is preferable to name it App.xaml since it is industry standard and adds consistency to all your projects.

 

 

 

Updated: