Qentinios
Qentinios

Reputation: 89

WPF accidentally deleted App.xaml

I have accidentally deleted App.xaml and App.xaml.cs from project solution. Now when I try to compile my program I get this error:

Error 1 Program 'xxx\WpfApplication1\obj\Release\Pacman Reloaded.exe' does not contain a static 'Main' method suitable for an entry point xxx\WpfApplication1\WpfApplication1\CSC WpfApplication1

I have tryed to copy & paste this files from another WPF project (I chave changed namespace and so on) but it haven't appeared in my solution explorer.

Adding new class and changing it's name to App.xaml does work neither.

What should I do to get my app working?

Upvotes: 3

Views: 5175

Answers (5)

Tim
Tim

Reputation: 1118

It is not enough to create a new class. You need a pair of xaml and xaml.cs files properly setup to work together. Create a new window called App. That will give you the files. Then modify them both to turn the window into an application:

App.xaml needs to look like this:

<Application x:Class="WpfApplication3.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         StartupUri="MainWindow.xaml">
    <Application.Resources>

    </Application.Resources>
</Application>

Of course WpfApplication3 must be replaced with your own application name.

Then make App.xaml.cs look like this, also changing WpfApplication3:

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

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

Lastly change the properties for App.xaml to make Build Action read ApplicationDefinition.

That should do it.

Upvotes: 5

Louie Aguilar
Louie Aguilar

Reputation: 62

you can find the deleted App.xaml in your recycle bin. Search it there then put it in your desktop then right click on your project/Solution in visual studio hover on add choose existing item, locate the App.xaml then click add.

Upvotes: 0

Qentinios
Qentinios

Reputation: 89

Ok, i solved it other way - i share my project on dropbox, and i have it on laptop and pc at the same time, so i disabled internet connection in my laptop, copied old version of my project, move it to my pc and changed code to my new version.. but even though thanks for help!

Upvotes: 0

sondergard
sondergard

Reputation: 3234

App.xaml has a code-behind file called app.xaml.cs - did you remember to include that? Also the app.xaml file should also be set to Build Definition "ApplicationDefinition" (right click -> properties). Finally, maybe you also need to update the startup object in the project properties.

If you copied the file from another project, select the project and click the "show all files" icon in the solution explorer, and include the missing files (see screen shot below).

Screen shot

Upvotes: 6

andreask
andreask

Reputation: 4298

If you just copy App.xaml and App.xaml.cs from another project using Windows Explorer, you need to also include it to your project by right-clicking the project in Solution Explorer and choose Add Existing Item and select those two files

Upvotes: 0

Related Questions