Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "Could not find xxxx.Program specified for main method" creating Windows Service from MS example

I am following this Microsoft guide to create a windows service.

However when I try and build it on the auto generated page called "Program.cs" That has this code in it

namespace BetfairBOTV2Service
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[] 
            { 
                new BrainiacVersion2() // not green though!!!!!
            };
            ServiceBase.Run(ServicesToRun);
        }
    }
}

I get this error "Could not find BrainiacV2.Program" specified for Main Method

I did everything the tutorial told me to.

I have an App.Config, a Program.cs (code above), a BrainiacV2.cs which holds all my code for the service and starts like this

namespace BetfairBOTV2Service
{
    public partial class BrainiacV2 : ServiceBase
    {
        public BrainiacV2()
        {
            InitializeComponent();

My ProjectInstaller.cs with two installer objects on them (name) serviceInstaller Display Name: My new BetfairBotV2 ServiceName: BrainiacVersion2

And that is that.

This is the only error I am getting

The solution is called BrainiacV2

I have tried changing the code in Program.cs to

new BrainiacV2()

which turns it green but then I just get

Could not find BrainiacV2.Program specified for main method.

What am I doing wrong or need to change?

Any help would be much appreciated - thanks!

Win 7, 64 bit, .NET 4.5, C#

like image 673
MonkeyMagix Avatar asked Aug 28 '14 18:08

MonkeyMagix


2 Answers

After renaming project and default namespace. I also had to change this:

enter image description here

So in your case at the creation of the project, the default Main was located in BrainiacV2.Program, but you do want to run Main in BetfairBOTV2Service.Program

like image 157
aeroson Avatar answered Oct 28 '22 11:10

aeroson


I had to change my namespaces and classes around. It was nothing to do with that error (not a very helpful one!)

namespace BrainiacV2
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[] 
            { 
                new Brainiac()
            };
            ServiceBase.Run(ServicesToRun);
        }
    }
}

Once I had done that it all worked!

A namespace issue it seems.

Would be nice if the error message was a bit more helpful though, as a lot of guess work was involved!

Thanks for your help.

like image 29
MonkeyMagix Avatar answered Oct 28 '22 11:10

MonkeyMagix