Convert Console Application to Windows Service

I have a console application with which I run SignalR. I am trying to convert it to a windows application.

I just changed the method Mainto

static void Main()
{
    var servicesToRun = new ServiceBase[] 
    { 
        new MyService() 
    };
    ServiceBase.Run(servicesToRun);
}

and added a class of service that is simple:

namespace Services
{
    partial class MyService : ServiceBase
    {
        IDisposable SignalR { get; set; }

        public MyService()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            const string url = "https://localhost:8080";
            using (SignalR = WebApp.Start<Startup>(url))
            {
                          //TODO: Add Logging
            }
        }

        protected override void OnStop()
        {
            SignalR.Dispose();
        }
          }
}

But now, when I try to run the installer, I get an error message:

An exception occurred during initialization of the installation: System.BadImageFormatException: Failed to load file or assembly 'file: /// C: \ Code \ MyCode \ Services \ bin \ Debug \ MyService.exe' or one of its dependencies. An attempt was made to download a program using the wrong format.

Is there an easy way to debug this post? Or does anyone have an idea of ​​what I might have missed?

+4
2

? , 32- 64-

, :

%windir%\Microsoft.NET\Framework\v4.0.30319\installutil.exe <My x64 DLL/EXE>

%windir%\Microsoft.NET\Framework64\v4.0.30319\installutil.exe <My x86 DLL/EXE>
+3

, " " , vs . ProjectInstaller serviceProcessInstaller1 serviceInstaller1 , , instalaction, Service Account, Name, Description .. installutil.exe , installutil

0

Source: https://habr.com/ru/post/1543262/


All Articles