16

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#

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
MonkeyMagix
  • 677
  • 2
  • 10
  • 30

5 Answers5

54

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

aeroson
  • 1,069
  • 13
  • 16
2

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.

MonkeyMagix
  • 677
  • 2
  • 10
  • 30
0

Looks like you're specifying the wrong class name. See the comments below.

namespace BetfairBOTV2Service
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
        {
            ServiceBase[] ServicesToRun;
            ServicesToRun = new ServiceBase[] 
            { 
                new BrainiacVersion2(); // <-- this is what you have
                new BrainiacV2();       // <-- this is what you need
            };
            ServiceBase.Run(ServicesToRun);
        }
    }
}

FWIW, I have a couple of tutorials - here and here - that show you how to create a service and have it install itself.

HTH

Community
  • 1
  • 1
Matt Davis
  • 45,297
  • 16
  • 93
  • 124
  • If u notice my comments in the first code snippet, I tried what u suggested and it goes green (the code) but I get the same error "could not find 'BrainiacV2.Program' specified for Main method – MonkeyMagix Aug 29 '14 at 10:39
0

I ran into the same issue some minutes ago, and while searching the web for an explanation, I came across this post. You might have found an answer over the years, but I'd like to share my solution. The error arrived at my project when I changed the namespace of the Program class. By aligning the startup project to the new namespace, my project is working again.

So, in your case, the startup-project should become BetfairBOTV2Service.Program.

0

IN my case i renamed my solution and many other files and gave this error . got solved : in csProj file the start-up file still had the older name which was now changed , so after changing it , I was able to build successfully.

gouravm
  • 301
  • 1
  • 12