Исключение, когда ASP.NET Core API размещается через WindowsServices - PullRequest
0 голосов
/ 28 ноября 2018

У меня есть исключение ниже после того, как первый запрос GET успешно выполнен и возвращен.

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 

Код ниже:

Проект - ASP.NET Core Web App -> WebAPI

открытый класс 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 файл ниже

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

Служба развертывания и хоста

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

Среда

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]
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...