Environment.Exit ends the whole process from code other than the program's entry point

tx0/csharp:process-exit-in-librarystrictwarningmaintainability/designdepth fastsmell

What it finds

Environment.Exit stops the process at once: callers get no chance to clean up, finally blocks of other threads do not run, and code that hosts the library, such as a test runner or a web server, dies with it. Throwing an exception, or returning an exit code to Main, leaves the decision to the program.

From the rule's source, process_exit_in_library.rs.

Example from the rule's tests
using System; class Config{    void Load(string path)    {        if (path == null)        {            Environment.Exit(1);tx0 reports: Environment.Exit ends the whole process here        }    }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:

tx0.toml
[rules]
"tx0/csharp:process-exit-in-library" = "warning"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/csharp:process-exit-in-library] reason="..."

tx0 explain tx0/csharp:process-exit-in-library shows the same in the terminal. Found a false positive? Report it.