Home > c#, WPF > Type ‘YourWPfApp.App’ already defines a member called ‘Main’ with the same parameter types

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.

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();
	}
}

The Problem

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

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

VN:F [1.9.22_1171]
Rating: 10.0/10 (11 votes cast)
Type 'YourWPfApp.App' already defines a member called 'Main' with the same parameter types, 10.0 out of 10 based on 11 ratings

Categories: c#, WPF Tags:
  1. No comments yet.
  1. No trackbacks yet.