Click here to Skip to main content
15,889,909 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I created a windows service with topshelf, mailkit and autofac nuget packages, I followed the topshelf documentation and can debug and install the service flawlesly on my local machine, but when I start to install as a service it on a windows server 2019 fails:

C:\inetpub\wwwroot\HorusCorreo>Horus.IntegradorCorreosRecibidos install

Excepción no controlada: System.IO.FileNotFoundException: No se puede cargar el archivo o ensamblado 'Autofac, Version=6.1.0.0, Culture=neutral, PublicKeyToken=17863af14b0044da' ni una de sus dependencias. El sistema no puede encontrar el archivo especificado.
   en Horus.IntegradorCorreosRecibidos.Program.Main(String[] args)



This is the code:

namespace Horus.IntegradorCorreosRecibidos
{
    class Program
    {
        static void Main(string[] args)
        {
            var builder = new ContainerBuilder();
           
            builder.RegisterModule<ProgramModule>();
            builder.RegisterModule<DependenciasUI>();
            var container = builder.Build();
            HostFactory.Run(serviceConfig =>
            {
                serviceConfig.UseAutofacContainer(container); 
                serviceConfig.UseNLog();
                serviceConfig.Service<Receptor>(serviceInstance =>
                {
                     
                    serviceInstance.ConstructUsing(() => container.Resolve<Receptor>());
                     serviceInstance.WhenStarted(execute => execute.Start());
                    serviceInstance.WhenStopped(execute => execute.Stop());
                    serviceInstance.WhenPaused(execute => execute.Pause());
                    serviceInstance.WhenContinued(execute => execute.Continue());
                });
                serviceConfig.EnableServiceRecovery(recoveryOption =>
              {
                  recoveryOption.RestartService(1);
            
              });
             
                serviceConfig.RunAsPrompt();
                serviceConfig.EnablePauseAndContinue();
                serviceConfig.SetServiceName("ReceptorCorreo");
                serviceConfig.SetDisplayName("Receptor de correos de Horus");
                serviceConfig.SetDescription("Receptor de correos de Horus");
                serviceConfig.StartAutomaticallyDelayed();
            });
        }
    }
}

However if a deploy it through the setup program, the console application works fine, any thoughts?

What I have tried:

I haver tested on my local machine, it installs as a service fine.
also on the server when I publish it like a regular console app it installes and runs perfectly
Posted
Updated 28-Apr-21 6:31am
Comments
Richard MacCutchan 28-Apr-21 11:45am    
"System.IO.FileNotFoundException"
You probably have a different version of some component on the local machine that is not installed on the server.

1 solution

Thank you Richard! Fortunately it was not that, here is the solution. I copied the entire bin/release folder from my developer machine to the server and then I installed the service.exe.
 
Share this answer
 
Comments
Richard Deeming 29-Apr-21 4:34am    
If you want to reply to a comment, click the "Reply" button next to the comment and reply.

Do not post your reply as a "solution" to your question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900