wpf The type name 'App' does not exist in the type ... occurs after renaming MainWindow

Wpf

Wpf Problem Overview


In a simple WPF, I have renamed MainWindow class to MyClass and I got this error in App.g.cs:

    public static void Main() {
        MyClass.App app = new MyClass.App();
        app.InitializeComponent();
        app.Run();
    }

How can I fix this can't find anything on the internet ?

Wpf Solutions


Solution 1 - Wpf

I accidentally got this error, in my case I had a class with the same name as the namespace. Renaming the class solved the problem.

Solution 2 - Wpf

Do not name a class the same as its namespace

Check out if you don't have a class somewhere in your project that has the same name as your namespace!

for example:

namespace HashCalculator
{
  public class HashCalculator

Solution 3 - Wpf

App.g.cs is produced by compiling App.xaml into C# code. The problem is in your App.xaml. Without seeing it, I can't be sure exactly what, but you probably just need to alter the StartupUri to StartupUri="MyClass.xaml".

Solution 4 - Wpf

You forgot to change the classname in MyClass.xaml (or MainWindow.xaml).

change it from

<Window x:Class="YourNamespace.MainWindow"

to

<Window x:Class="YourNamespace.MyClass"

Solution 5 - Wpf

Johan's answer + Also check if you have a folder with the same name as your solution.

Solution 6 - Wpf

In my case I needed to install the .NET Framework 4.8 Runtime and Targeting Pack.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser310291View Question on Stackoverflow
Solution 1 - WpfJohan LarssonView Answer on Stackoverflow
Solution 2 - WpfLegendsView Answer on Stackoverflow
Solution 3 - WpfTergiverView Answer on Stackoverflow
Solution 4 - WpfthumbmunkeysView Answer on Stackoverflow
Solution 5 - WpfSZTView Answer on Stackoverflow
Solution 6 - Wpfuser8128167View Answer on Stackoverflow