0

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!).

1 Answer 1

1

That is not supported yet as it is stated here

Sign up to request clarification or add additional context in comments.

3 Comments

I found the complete "recipe" for asp.net core 2.0 at learn.microsoft.com/en-us/aspnet/core/host-and-deploy/…
that link states that .Net Framework 4.6.1 Template is needed "When creating a project in Visual Studio, use the ASP.NET Core Application (.NET Framework) template"
If this answer gave you enough information please consider to mark it as solution.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.