I try to run a asp.net core 2 web api as a windows service. I'm targeting .Net 4.6.1 Framework. I created a basic project from visual studio template, by not changing anything except Program.cs Main method to
public static void Main(string[] args)
{
var pathToExe = Process.GetCurrentProcess().MainModule.FileName;
var pathToContentRoot = Path.GetDirectoryName(pathToExe);
var host = WebHost.CreateDefaultBuilder(args)
.UseContentRoot(pathToContentRoot)
.UseStartup<Startup>()
.Build();
host.RunAsService();
}
When I try to start my windows service, I get the foloowing error in event viewer
Version du Framework : v4.0.30319
Description : le processus a été arrêté en raison d'une exception non gérée.
Informations sur l'exception : System.TypeLoadException
Pile :
à Microsoft.AspNetCore.Hosting.WebHostBuilder.BuildCommonServices(System.AggregateException ByRef)
à Microsoft.AspNetCore.Hosting.WebHostBuilder.Build()
à deploy.Program.Main(System.String[])
Any clue what's happening here ? I deployed numerous web api as web service without problems in the past, but they all were built on asp.net core 1.0.
UPDATE
Ends up that hosting machine didn't have .Net Framework 4.6.1 installed (duh!).