Skip to content
This repository has been archived by the owner on Dec 19, 2018. It is now read-only.

New ASP.NET Core 2.0 application fails at host.RunAsService() #1173

Closed
epicbugs opened this issue Aug 17, 2017 · 4 comments
Closed

New ASP.NET Core 2.0 application fails at host.RunAsService() #1173

epicbugs opened this issue Aug 17, 2017 · 4 comments

Comments

@epicbugs
Copy link

I recently updated my Visual Studio 2017 to 15.3 which means I got the opportunity to try out the new Core 2.0 SDK. It was easy enough but as soon as I tried running it as a Windows Service, I got into trouble.

I have followed the official guideline https://docs.microsoft.com/en-us/aspnet/core/hosting/windows-service to the dot (no pun intended) but the new SDK seems to be different and possibly buggy:

  1. I get a DLL as build output instead of an EXE (which kind of makes sense, being crossplatform, but the documentation clearly states it has to be an EXE)
  2. when I run the DLL as a Windows Service, it fails to start
  3. when I run the app either from VS2017 or with dotnet MyApp.dll, it throws an exception

The exception I get is:

Unhandled Exception: System.TypeLoadException: Could not load type 'System.ServiceProcess.ServiceBase' from assembly 'System.ServiceProcess, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.
   at Microsoft.AspNetCore.Hosting.WindowsServices.WebHostWindowsServiceExtensions.RunAsService(IWebHost host)
   at Program.Main(String[] args) in C:\...\...\Program.cs:line 39

I have verified that all files from the build output are present, including Microsoft.AspNetCore.Hosting.WindowsServices.dll, so as far as I understand, everything should be there. Also, the System.ServiceProcess.dll file itself is present in all .NET framework installation directories.

Here's the target framework information:

<TargetFramework>netcoreapp2.0</TargetFramework>

Here's the Program.cs:

public class Program
{
    public static void Main(string[] args)
    {
        var pathToExe = Process.GetCurrentProcess().MainModule.FileName;
        var pathToContentRoot = Path.GetDirectoryName(pathToExe);

        var host = new WebHostBuilder()
        .UseKestrel()
        .UseContentRoot(pathToContentRoot)
        .UseIISIntegration()
        .UseStartup<Startup>()
        .UseApplicationInsights()
        .Build();

        host.RunAsService(); // <--- here is where the exception gets thrown
    }
}
  • If this is a bug then can someone please confirm this behavior on their own machine?
  • If this is a feature then what should I do to get it working as intended?

I am experiencing this on a Windows 10 Professional (version 15063.540) running the latest stable Visual Studio 2017 (version 15.3) with .NET Core 2.0 SDK fully installed.

@davidfowl
Copy link
Member

This package only supports .NET Framework. See https://www.nuget.org/packages/Microsoft.AspNetCore.Hosting.WindowsServices/. Open up the dependencies tab you'll see it's .NET Framework 4.6.1 only.

@JunTaoLuo
Copy link
Contributor

Core support pending #904

@mlashgarbolok
Copy link

mlashgarbolok commented Oct 7, 2017

i get exactly @epicbugs 's error too.
what should i do??
does it now works on .net core or still on .net framework??

@Tratcher
Copy link
Member

Tratcher commented Oct 7, 2017

It's still .NET framework only. See #904

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants