3

When I create new WPF stand-alone app from template in VS 2013, I could not start it in debug for this exception.

error CS5001: Program 'XYZ' does not contain a static 'Main' method suitable for an entry point. The command exited with code 1.

Although I checked out if App.xaml is build as ApplicationDefinition = true, project is with 'Windows Application' output type, I reinstall all templates from command line, I am running brand new (reinstalled) VS 2013 with .net 4.5 and all project templates seems to be okay. And problem still occurs.

Anybody else is having this one too? There are similar questions with answers but no one did help me. So it's not a duplication (moderators).

I did not want to create new thread for answers but after moderators down vote and delete this question in similar thread I had to.

st35ly
  • 1,215
  • 18
  • 24

1 Answers1

2

Your application must contain App.xaml.cs file in project code directory such as this

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace Lab2
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
    }
}

and in the child directory with path obj\(Debug or Release)\

the files with names (App.i.g.cs) (App.g.cs) with content like this

#pragma checksum "..\..\App.xaml" "{406ea660-64cf-4c82-b6f0-42d48172a799}" "E9A260C0E00B01D8D305634A08B2F0E3"
//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.17929
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Automation;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Markup;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Effects;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;
using System.Windows.Media.TextFormatting;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Shell;


namespace Lab2 {


    /// <summary>
    /// App
    /// </summary>
    public partial class App : System.Windows.Application {

        /// <summary>
        /// InitializeComponent
        /// </summary>
        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
        public void InitializeComponent() {

            #line 4 "..\..\App.xaml"
            this.StartupUri = new System.Uri("View/MainWindow.xaml", System.UriKind.Relative);

            #line default
            #line hidden
        }

        /// <summary>
        /// Application Entry Point.
        /// </summary>
        [System.STAThreadAttribute()]
        [System.Diagnostics.DebuggerNonUserCodeAttribute()]
        [System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
        public static void Main() {
            Lab2.App app = new Lab2.App();
            app.InitializeComponent();
            app.Run();
        }
    }
}

the solution of the problem can be find in No Main() in WPF?

Community
  • 1
  • 1
Mykola
  • 3,343
  • 6
  • 23
  • 39
  • I have looked into the obj/Debug folder and I can see that App.xaml.g.i.cs file is not generated. Then I switch 'build action' from ApplicationDefinition into Page and file showed up. Of course with no Main() entry point in it. Not sure why its not get generated during project compiling when 'ApplicationDefinition'. Also in App.xaml have set StartupUri to righ main page. And still the same exception. What really works is to set App.xaml as Page and implement own Main which u set in project properties as starting point. But why it works on my second pc without that? Any other ideas? – st35ly Oct 08 '15 at 21:54
  • thanks for a tip with 'No Main() in WPF?' but except the last comment where u basically create your own Main method no other reply work for me – st35ly Oct 08 '15 at 21:55
  • If it compiles on other PCs, than there is something wrong with current copy of Visual Studio (maybe with its configuration). I not certain, but simple reinstall may help you this issue. – Mykola Oct 08 '15 at 22:06
  • I tried this too. VS and templates reinstalled and still problem occurs :/ Anything else as a tip to try? – st35ly Oct 08 '15 at 23:24