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

C#Wpf

C# Problem Overview


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.

C# Solutions


Solution 1 - C#

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

Solution 2 - C#

Maybe the "Output type" in properties->Application of the project must be a "Class Library" instead of console or windows application.

Solution 3 - C#

Just in case anyone is having the same problem... I was getting this error, and it turned out to be my <Application.Resources> in my App.xaml file. I had a resource outside my resource dictionary tags, and that caused this error.

Solution 4 - C#

In my case (after renaming application namespace manually) I had to reselect the Startup object in Project properties.

Solution 5 - C#

You can also run into this if you're working on a WPF project that was started in VS 2010 (Beta 1), then moved into VS 2008.

Under the project properties, the .NET framework version gets unset (since .NET 4.0 isn't valid in VS 2008), and for some reason that causes this error.

If you set the .NET framework (e.g. to .NET 3.5), the error goes away.

Solution 6 - C#

Just in case someone is still getting the same error, even with all the help above: I had this problem, I tried all the solutions given here, and I just found out that my problem was actually another error from my error list (which was about a missing image set to be my splash screen. i just changed its path to the right one and then all started to work)

Solution 7 - C#

I have got the same error but then I found out that I typed small m instead of capital M in Main method

Solution 8 - C#

Project Properties \ Output file -> Select Class Library :)

Solution 9 - C#

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.

Solution 10 - C#

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">

Solution 11 - C#

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionChristopherView Question on Stackoverflow
Solution 1 - C#Kent BoogaartView Answer on Stackoverflow
Solution 2 - C#Kervin RamenView Answer on Stackoverflow
Solution 3 - C#AndyAView Answer on Stackoverflow
Solution 4 - C#EugeneView Answer on Stackoverflow
Solution 5 - C#Ryan LundyView Answer on Stackoverflow
Solution 6 - C#leoneboaventuraView Answer on Stackoverflow
Solution 7 - C#Arun PandeyView Answer on Stackoverflow
Solution 8 - C#pixparkerView Answer on Stackoverflow
Solution 9 - C#Faraz Ahmed QureshiView Answer on Stackoverflow
Solution 10 - C#crakamaView Answer on Stackoverflow
Solution 11 - C#SYED NAWAZ PRINCEView Answer on Stackoverflow