Reputation: 28739
I have a test suite, with a Main function that returns 1. However, the exit code after the application terminates is 0.
This seems to be related to a ASP.NET server I'm running in the background. If I disable the server, the exit code is 1 as expected.
This code works as expected, and the console reports an exit code of 1 (this is F# syntax, but I'm pretty sure that's not related):
[<EntryPoint>
let main (arts : string array) : int =
1
while this has an exit code of 0, which is not what I expect:
[<EntryPoint>
let main (arts : string array) : int =
MyHttpServer.init()
1
Here's the MyHttpServer.init function:
let init() : Task =
Host
.CreateDefaultBuilder()
.Build()
.RunAsync()
My question: what is it about having a server running in the background that is causing the exit code to be zero? Is there something in .NET where the exit code is affected by background tasks and threads?
Note: .NET 6 preview 5, but this has happened on all versions I've used from .NET 5 onwards.
Upvotes: 1
Views: 456
Reputation: 136
Not super familiar with F# syntax, BUT I suspect that if Init() exits b/c of an error/exception, then execution would never reach the line returning a 1, and would therefore exit with a value of 0.
EDIT:
If an exception is thrown when calling Init
, or if an exception is thrown before Init
can return, the unhandled exception would terminate the process, and the code that returns 1
would not be executed.
Upvotes: 1