I recently ran into an interesting aspect of WPF applications that I had not previously seen. It started with this error:
Program 'DemoCorp.UI.exe' does not contain a static 'Main' method suitable for an entry point
I had copied an App.xaml file from an existing application into a new application I was creating, because I wanted the resource definitions and thought that would be an easy way to do it. I then deleted the App.xaml that was automatically generated in the new application, which created the compiler error above.
As it turns out, there's a special output type for the App.xaml file to make it generate the Main method. Here's an App.xaml in the solution explorer:
If you click on the properties tab to get the file properties for the App.xaml, you'll see something like the following:
To generate a suitable Main method, the Build Action must be set to ApplicationDefinition as shown in this image. As soon as I figured this out, everything worked great.



12 comments:
Sweet, thanks for the insight Joe. I love your posts the point out the solutions to "odd" problems. It really helps the rest of us find the answer quickly. Keep up the good work man.
Thank you. I was stuck and wondering what is wrong with my build.
-sri
Went through the EXACT steps you did and got stuck. Thanks for the help.
Thanks. That was exactly the problem I had.
You and google are my heroes. You for this post, and google for helping me find it.
thank you very much Joe!
Thank you. Someone suggested changing my Build action to page in another article and as a result I started getting this error. This is exactly what I needed to know.
Thanks a lot. I was worried to see that message thinking i have done something terrible :)
Thanks a lot
Exactly what I was looking for- thanks!
Thanks a lot. Your solution is very useful. I was so happy after solving the problem.
Thanks, you just saved my day
I thought I would end up spending an hour googling for an answer, yours was the first hit with exactly what i needed, thanks so much...
Post a Comment