Type ‘YourWPfApp.App’ already defines a member called ‘Main’ with the same parameter types

Create your own Custom Splash Page

In WPF you can really easily create a basic splash page which is just an image, but it is a bit simple for most people.

In my application I want to display a marquee style progress bar, application version numbers that are generated off the Assembly version number, and perform any application start up, like validate a license.

So create yourself a WPF window SplashPage.xaml and implement your layout and any custom code that should run inside the splash page.
Implement a timer so the window will remain open for a period of time. When the timer ticks, if all the work is done, close and dispose of the timer and then close the splash window.

Place this code in your App.xaml.
[csharp]
public partial class App : Application
{
/// <summary>
/// Application Entry Point.
/// </summary>
[System.STAThreadAttribute()]
[System.Diagnostics.DebuggerNonUserCodeAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("PresentationBuildTasks", "4.0.0.0")]
public static void Main()
{
ShowSplashScreen();
YourWpfApp.App app = new YourWpfApp.App();
app.InitializeComponent();
app.Run();
}

protected static void ShowSplashScreen()
{
SplashPage splash = new SplashPage();
splash.ShowDialog();
splash.Close();
}
}
[/csharp]

The Problem

When you build the program you will get an error like:

Type 'YourWPfApp.App' already defines a member called 'Main' with the same parameter types

When you click on the error it will take you to a page App.g.cs, which contains a duplicate static Main() application entry point, that is generated by VisualStudio.

The Solution

  1. Go to the properties of the App.xaml page.
  2. Check the Build Action. It will be “Application Definition”
  3. Change the build action to “Page”
  4. Build the application

The application will now build. The App.g.cs file will be updated and when you look it will no longer contain the Main method.

Cheers

3 thoughts on “Type ‘YourWPfApp.App’ already defines a member called ‘Main’ with the same parameter types

  1. Thank you very much!
    It’s so funny that I confused with Project property with xaml property,
    I am noob that i didn’t realize a xaml will have property.
    Succeed util second time to get here.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.