通过WindowsServices托管ASP.NET Core API时发生异常

时间:2018-11-28 11:49:18

标签: asp.net-web-api asp.net-core .net-core asp.net-core-2.0

在成功发出并返回第一个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-> Web API

公共课程     {

    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]

0 个答案:

没有答案