Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Application.OnStartup not being called?

Tags:

c#

wpf

.net-4.0

I have a WPF .NET 4 application where I override the OnStartup method in order to process the file passed to my application. However, it seems that this method is not being called when the application runs. I put an exception in there and even a breakpoint and it starts up and completely ignores this.

Am I missing something?

Code for App.xml.cs:

/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
    protected override void OnStartup(StartupEventArgs e)
    {
        throw new NotImplementedException();
    }
}

Contents of App.xaml:

<Application x:Class="XGN_Image_Downloader.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>

EDIT: Found it! The x:Class attribute in App.xaml did not match the App.xaml.cs class :) That's what you get for coding while drinking wine. (Thanks to this thread: WPF app startup problems)

like image 965
Jonas Van der Aa Avatar asked May 05 '11 04:05

Jonas Van der Aa


2 Answers

Found it, I had to set the x:Class attribute in App.xaml to the same class as the App.xaml.cs class. This was an error caused by bad refactoring on my side.

like image 71
Jonas Van der Aa Avatar answered Nov 08 '22 04:11

Jonas Van der Aa


x:Class must be filled with the namespace and exact class name on App.xml.cs

Eg: <Application x:Class="Namespace.ClassName"

like image 1
Chamath Jeevan Avatar answered Nov 08 '22 04:11

Chamath Jeevan