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