Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to recover project after deleting App.xaml?

Tags:

c#

wpf

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?

like image 733
Qentinios Avatar asked Oct 21 '25 05:10

Qentinios


2 Answers

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

like image 168
sondergard Avatar answered Oct 23 '25 20:10

sondergard


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.

like image 22
Tim Avatar answered Oct 23 '25 18:10

Tim