How to fix WPF error: "Program does not contain a static 'Main' method suitable for an entry point"?

Viewed 149702

Suddenly my whole project stopped compiling at all, showing the following message:

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

I made no changes to project properties, just added some classes, moved some other classes into folders. Its an WPF Application project so it should be all OK. Entry point is where it should be, file App.xaml was not modified at all :(

What should I do to make it work again?

NOTE
For reference: if renaming the App.xaml this can happen. As OP stated, App.xaml was not altered; however, this is added for anyone that does rename the App.xaml.

12 Answers

Check the properties of App.xaml. Is the Build Action still ApplicationDefinition?

It is also possible to get this kind of error when working on WPF/UPF application and in your project's .csproj uses wrong SDK i.e <Project Sdk="Microsoft.NET.Sdk"> instead of <Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">

I have faced the problem while changing .net framework v4.7.2 to .net core 3.1, and solved by adding

<PropertyGroup>
    <UseWPF>true</UseWPF>   
</PropertyGroup>

in .csproj

I have seen this error message when App.xaml (left-click) Properties/BuildAction was set to Page. Setting it to ApplicationDefinition solved the issue

As what, I guess pixparker wanted to say, but remained to be not clear enough, for me at least, do ensure that... All "Other Projects" have an "Output Type" of "Class Library" selected while... Only "One Project" being selected as either "Window Application" or "Console Application" output.

Related