title: Kestrel error: address already in use (dotnet core)
body: <p>Summary: it works as <code>dotnet run</code>, but it doesn't work as <code>dotnet myappname.dll</code>.</p>
  
  <p>My linux skills are limited, but I am trying to go by the book so I don't mix things up (following <a href="http://www.hanselman.com/blog/PublishingAnASPNETCoreWebsiteToACheapLinuxVMHost.aspx" rel="noreferrer">this tutorial</a> from Scott Hanselman):</p>
  
  <pre><code>$ cd /home/myusername/dotnettest
  $ dotnet run
  </code></pre>
  
  <blockquote>
    <p>Now listening on: <a href="http://localhost:5123" rel="noreferrer">http://localhost:5123</a></p>
  </blockquote>
  
  <p>Then I move it to /var like so:</p>
  
  <pre><code>$ sudo cp -a /home/myusername/dotnettest/bin/Debug/netcoreapp1.1/publish /var/dotnettest
  </code></pre>
  
  <p>Finally I test if it works there as well:</p>
  
  <pre><code>$ dotnet dotnettest.dll
  </code></pre>
  
  <p>Then it fails:</p>
  
  <pre><code>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) ---&gt; 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.&lt;&gt;c.&lt;StartAsync&gt;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)
  </code></pre>
  
  <p>I've been careful in trying to stop nginx.</p>
  
  <p>I've checked if anything is listening to :5123 with the command:</p>
  
  <pre><code>$ lsof -i tcp:5123
  </code></pre>
  
  <p>And nothing seems to come up.</p>