Program does not contain a static 'main' m

2019-07-08 08:27发布

I know that this question has been asked a lot, but none of the solutions seem to work for me. That or I am just incompetent and need to have my hand held through this problem (most likely solution). I looked through all of the classes, and all the build actions are set to compile, so I have no idea what could have gone wrong. Any help?

Additional Details: I have been coding the starting of a game, and everything was going good until I got this error:

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

All progress on this project has halted since this error appeared, and I could not find a way to fix it anywhere.

5条回答
老娘就宠你
2楼-- · 2019-07-08 09:14

I started getting this error on a WPF4/VS2010/MVVMLight app. All suggestions came up fruitless, until I came to the one about creating a new app and comparing the project and XAML files. This sounded like a desperate stab in the dark, but I went ahead and tried it.

After looking at several other files (thank heaven for BeyondCompare!), I discovered that my App.xaml had acquired an extra resource dictionary:

    <Application.Resources>
      <!--Global View Model Locator-->
      <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
      <ResourceDictionary>
        <vm:ViewModelLocator x:Key="Locator" d:IsDataSource="True" />
        <ResourceDictionary.MergedDictionaries></ResourceDictionary.MergedDictionaries>
      </ResourceDictionary>
    </Application.Resources>

Removing the ResourceDictionary block fixed the problem. I still have no idea how this occurred (I wasn't editing app.xaml when this started), and it's not clear why VS reported this as the "static 'Main' method" error. Very strange.

查看更多
叛逆
3楼-- · 2019-07-08 09:16

Had this same problem. Solution: Be sure the app.xaml properties "Build Action" is set to ApplicationDefinition

查看更多
beautiful°
4楼-- · 2019-07-08 09:20

Faced the same problem. But in my case I had to create a WPFApplication but was creating a class library. And upon building the same was getting this error. Try creating a WPF application. Hope it helps.

查看更多
劳资没心,怎么记你
5楼-- · 2019-07-08 09:22

Just faced the same problem and following solution solve my problem: If you are using multilayer projects, Right click on the project throwing error and go to properties go to Application Tab and set output type to Class Library and then problem will be solved.

查看更多
Rolldiameter
6楼-- · 2019-07-08 09:24

Try this answer here, it's close to what you have, and few things mentioned,

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

In short you got something 'out of sync' regarding your WPF setup, App.xaml or maybe MainWindow etc. or how you build the project etc.

(note: the main entry point should be auto-generated, that's the temp file I talked about in the comments - if all is ok, if something's is changed etc. then it doesn't generate and it fails)

Go thru all and make sure - or build an empty WPF project, try with that then compare what's different, minimize the differences, narrow down.

hope this helps

查看更多
登录 后发表回答