Self-contained win-x64 executable AggregateException: Connection actively refused

  .net, aggregateexception, core, self-contained, windows

I am trying to publish a self-contained executable for Windows. When I try to run the executable via a privileged powershell (or cmd) window, I get the following error:

Unhandled exception. System.AggregateException: One or more errors occurred. (No connection could be made because the target machine actively refused it.)
 ---> System.Net.Http.HttpRequestException: No connection could be made because the target machine actively refused it.
 ---> System.Net.Sockets.SocketException (10061): No connection could be made because the target machine actively refused it.
   at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
   --- End of inner exception stack trace ---
   at System.Net.Http.ConnectHelper.ConnectAsync(String host, Int32 port, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean allowHttp2, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.CreateHttp11ConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.GetHttpConnectionAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken)
   at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task`1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts)
   --- 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 System.Threading.Tasks.Task.Wait()
   at myProgram.Client.postClaim(Claim Claim, Byte[]& var1, Byte[]& var2, Byte[]& var3)
   at myProgram.Program.Main(String[] args)

If it’s relevant, on that line, I am connecting to a tomcat-hosted server on another machine.

What is strange, is that when I publish a non-standalone app, I don’t get the error. The application runs successfully to completion. I also don’t get the error when I run the program in debug mode from within visual studio. Additionally, I’ve built a self-contained executable for linux-x64, and that was able to run successfully from a linux machine.

I’ve tried disabling Windows Defender firewall, and similar programs. However, since the program runs fine in those other cases, I’m thinking it’s not a firewall issue.

Is there a problem with self-contained executables? Is there something I’m missing before running the self-contained executable on windows? I’m at a loss on how to solve this issue.

Thank you for your assistance.

Source: Windows Questions

LEAVE A COMMENT