Question

I have a WPF project which I try to make it a single instance app using the recipe with Microsoft.VisualBasic dll described by Dale Ragan here at StackOverflow

Doing so in Visual Studio 2013 with Framework 4.5 give me 2x the same error while compiling: "... has more than one entry point defined..." for each entry point. Then I though that I would see both entry points in the comboBox choices of my "Startup Object" item of "Application" tab of my project properties. But it is empty. Why the "StartUp object" comboBox is empty and how to set the entry point? Could it be a Microsoft bug?

Additional information: - The 2 files with entry points are "App.g.cs" (auto generated) and my newly defined class with entry point - main : "EntryPoint.cs"

Was it helpful?

Solution 2

Sorry folks,

The problem disappeared. I restarted Visual Studio but I had same behavior. I made a new project to send to Microsoft as a bug but it was working fine. I then copied my startup class from my test project and the bug disappeared ????????? I don't understand.

OTHER TIPS

I've solved the problem by hacking the csproj file:

<PropertyGroup>
  <StartupObject>Test.Program</StartupObject>
</PropertyGroup>

You can follow these steps (For an EntryPoint):

  • Right Click in your solution, Properties, Common Properties, Startup Project, and select your Startup Project there.
  • Open your app.xaml and set the StartUpUri to your Main XAML file.
  • Unload your WPF project, and after that Edit it!

In App.xaml.cs file you can put these lines of code:

using System.Diagnostics;
...
Process[] activeProcess = Process.GetProcessByName(Process.GetCurrentProcess().ProcessName);
if (activeProcess.Length == 1)
{
    Application.Run(new YOUR_MAIN_XAML_CLASS_HERE());
}
else
{
    MessageBox.Show("You already have an instance of this program");
}

Hope it helps

It's hard to predict without reviewing the code. However, ensure following points are covered.

Create a class that derives from Microsoft.VisualBasic.ApplicationServices. WindowsFormsApplicationBase, and use it to wrap your WPF System.Windows.Application. The wrapper is initialized by supplying your own implementation of Main.

namespace SingleInstanceNamespace
{
    using System;
    using System.Windows;
    using Microsoft.VisualBasic.ApplicationServices;

    public class SingleInstanceManager : WindowsFormsApplicationBase
    {
        public SingleInstanceManager()
        {
            this.IsSingleInstance = true;
        }

        protected override bool OnStartup(
            Microsoft.VisualBasic.ApplicationServices.StartupEventArgs eventArgs)
        {
            base.OnStartup(eventArgs);
            App app = new App(); //Your application instance
            app.Run();
            return false;
        }

        protected override void OnStartupNextInstance(
            StartupNextInstanceEventArgs eventArgs)
        {
            base.OnStartupNextInstance(eventArgs);
            string args = Environment.NewLine;
            foreach (string arg in eventArgs.CommandLine)
                {
                args += Environment.NewLine + arg;
                }
            string msg = string.Format("New instance started with {0} args.{1}",
            eventArgs.CommandLine.Count,
            args);
            MessageBox.Show(msg);
        }
    }
}

The next code block details the content of the App.cs file where the application’s main entry point is defined:

namespace SingleInstanceNamespace
{
    public class MyApp
    {
        [STAThread]
        public static void Main(string[] args)
        {
            //Create our new single-instance manager
            SingleInstanceManager manager = new SingleInstanceManager();
            manager.Run(args);
        }
    }
}

In my case, the forms were missing too from the Startup object dropdown list. So, I found another easey way to modify the startup form.

  1. Open the Program.cs file on Code View
  2. Go to the static void Main()
  3. Modify the line that looks like the following:

Application.Run(new Form1());

To your desired Form, like this:
Application.Run(new BootloaderDialog());

Hope this helps!

In my case, I spelled entry name Main() to main(), then this entry not added into startup object list.When I changed it to Main(), the entry was added into startup object list. So be careful case sensitive.

I wanted "MyMainWindow" to be the starting element for "MyProject" project.

In App.xaml had to set:

<Application x:Class="MyProject.App"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:local="clr-namespace:MyProject"
         StartupUri="MyMainWindow.xaml">
<Application.Resources>
     
</Application.Resources>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top