Exception when ASP.NET Core API hosted via WindowsServices

0

I have got the exception below after the first GET request is successfully made and returned.

Application: ASPCore.exe
CoreCLR Version: 4.6.27019.6
Description: The process was terminated due to an unhandled exception.
Exception Info: System.InvalidOperationException: 'overlapped' has already been freed.
   at System.Threading.ThreadPoolBoundHandleOverlapped.CompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* nativeOverlapped)
   at System.Threading._IOCompletionCallback.PerformIOCompletionCallback(UInt32 errorCode, UInt32 numBytes, NativeOverlapped* pOVERLAP)


Faulting application name: ASPCore.exe, version: 0.0.0.0, time stamp: 0x5bca0f4b
Faulting module name: KERNELBASE.dll, version: 6.1.7601.24260, time stamp: 0x5b9470f4
Exception code: 0xe0434352
Fault offset: 0x000000000000bded
Faulting process id: 0x5154
Faulting application start time: 0x01d486f85afbf4a0
Faulting application path: C:\ASPCore.exe
Faulting module path: C:\WINDOWS\system32\KERNELBASE.dll
Report Id: 9f0ce960-f2eb-11e8-8e6c-fb5a9f1903c6 

Code below:

The project is ASP.NET Core Web App -> Web API

public class Program {

    public static void Main(string[] args)
    {
        var isService = !(Debugger.IsAttached || args.Contains("--console"));
        var builder = CreateWebHostBuilder(args.Where(arg => arg != "--console").ToArray());

        if (isService)
        {
            var pathToExe = Process.GetCurrentProcess().MainModule.FileName;
            var pathToContentRoot = Path.GetDirectoryName(pathToExe);
            //use a path to the app's published location instead of Directory.GetCurrentDirectory().
            builder.UseContentRoot(pathToContentRoot);
        }

        var host = builder.Build();

        if (isService)
        {
            host.RunAsService();
        }
        else
        {
            host.Run();
        }
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args)
    {
        var configuration = new ConfigurationBuilder()             
            .AddJsonFile("appsettings.json", optional: true)              
            .Build();

        return WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>()
             .UseConfiguration(configuration);          
    }
}

appsettings.json

{
  "urls": "http://*:6001;",
}

*.proj file below

 <TargetFramework>netcoreapp2.1</TargetFramework>
    <RuntimeIdentifiers>win7-x64;</RuntimeIdentifiers>

Deploy and host service

dotnet publish --configuration Release --self-contained -r win7-x64 --output C:\ASPCore
sc create ASPCore binPath= "C:\ASPCore\ASPCore.exe" 
sc start ASPCore
sc delete ASPCore

Environment

Windows 7

dotnet --list-runtimes

Microsoft.AspNetCore.All 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
asp.net-web-api
asp.net-core
.net-core
asp.net-core-2.0
asked on Stack Overflow Nov 28, 2018 by Pingpong • edited Nov 28, 2018 by Pingpong

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0