wpf The type name 'App' does not exist in the type ... occurs after renaming MainWindow
WpfWpf 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.