Okay, i've written a Console application and it works. This is the code.
static void Main(string[] args)
{
IceMain.Instance.Start();
Console.ReadLine();
IceMain.Instance.Stop();
IceMain.Instance.Term();
}
Now, when i write a C# Windows Service, and try to start the service. It didn't work. This is the Windows service code...
public partial class Service1 : ServiceBase
{
public Service1()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
IceMain.Instance.Start();
}
protected override void OnStop()
{
IceMain.Instance.Stop();
IceMain.Instance.Term();
}
}
Of course, i gave it a service name, sid, and setup things correctly. But when i did the net start sid it gave me:
Microsoft (R) .NET Framework Installation utility Version 4.8.3752.0 Copyright (C) Microsoft Corporation. All rights reserved. Exception occurred while initializing the installation:
System.BadImageFormatException: Could not load file or assembly 'file:///C:\Project\sptrader_dotnet\ICEService\IcePrice\bin\Debug\IcePrice.exe' or one of its dependencies. An attempt was made to load a program with an incorrect format.. The service name is invalid.
More help is available by typing NET HELPMSG 2185.
All I know is that the underlying application also depends on several x64 C++ DLLs. But i did set my service to compile in x64 platform, and made sure those Dlls are in the sample folder, but the service still cannot run, while in the Console application, it works.
How is that, and how can i fix it to run on a windows service? It doesn't seem like it has anything to do with my service name, as I've written many windows service before and it all works, but for this case it involves some C++ DLLs.