c# – Kestrel错误:地址已在使用中(dotnet core)

摘要:它可以作为dotnet运行,但它不能用作dotnet myappname.dll.

我的linux技能是有限的,但我试图通过这本书,所以我不混淆(跟随Scott Hanselman this tutorial):

$cd /home/myusername/dotnettest
$dotnet run

Now listening on: 07001

然后我把它移动到/ var就像这样:

$sudo cp -a /home/myusername/dotnettest/bin/Debug/netcoreapp1.1/publish /var/dotnettest

最后我测试它是否也在那里工作:

$dotnet dotnettest.dll

然后它失败了:

info: Microsoft.Extensions.DependencyInjection.DataProtectionServices[0]
      User profile is available. Using '/home/myusername/.aspnet/DataProtection-Keys' as key repository; keys will not be encrypted at rest.

Unhandled Exception: System.AggregateException: One or more errors occurred. (Error -98 EADDRINUSE address already in use) ---> Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvException: Error -98 EADDRINUSE address already in use
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.Libuv.Check(Int32 statusCode)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Networking.UvTcpHandle.GetSockIPEndPoint()
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.TcpListener.CreateListenSocket()
   at Microsoft.AspNetCore.Server.Kestrel.Internal.Http.Listener.<>c.<StartAsync>b__6_0(Object state)
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at Microsoft.AspNetCore.Server.Kestrel.Internal.KestrelEngine.CreateServer(ServerAddress address)
   at Microsoft.AspNetCore.Server.Kestrel.KestrelServer.Start[TContext](IHttpApplication`1 application)
   at Microsoft.AspNetCore.Hosting.Internal.WebHost.Start()
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host, CancellationToken token, String shutdownMessage)
   at Microsoft.AspNetCore.Hosting.WebHostExtensions.Run(IWebHost host)
   at WebApplication.Program.Main(String[] args) in /home/myusername/dotnettest/Program.cs:line 27
Aborted (core dumped)

我一直小心翼翼地试图阻止nginx.

我已检查是否有任何内容正在侦听:5123使用命令:

$lsof -i tcp:5123

似乎什么都没有出现.

最佳答案
以下命令有助于查找端口并终止进程

Mac上的终端

找到进程号

lsof -i: <port number>

例如lsof -i:5001

然后杀死进程号

kill -9 <process number>

例如 – kill -9 1600

转载注明原文:c# – Kestrel错误:地址已在使用中(dotnet core) - 代码日志