Microsoft KB Archive/320165

= BUG: Incorrect Exit Code Displayed in Output Window When Application Run Under Debugger =

Article ID: 320165

Article Last Modified on 5/28/2003

-

APPLIES TO


 * Microsoft Visual C# .NET 2002 Standard Edition
 * Microsoft Visual C# .NET 2003 Standard Edition

-



This article was previously published under Q320165



SYMPTOMS
Incorrect process exit code may be displayed in the Output window when you run an application under the managed debugger.



RESOLUTION
Do not use the debugger Output window to obtain the exit status of an application. Run the application from a batch file to obtain the return value, as follows: REM Exit_Error.bat @echo off ConsoleApplication1.exe IF ERRORLEVEL 2 IF NOT ERRORLEVEL 3 echo Exit Value 2 IF ERRORLEVEL 1 IF NOT ERRORLEVEL 2 echo Exit Value 1 IF ERRORLEVEL 0 IF NOT ERRORLEVEL 1 echo Exit Value 0 IF ERRORLEVEL -1 IF NOT ERRORLEVEL 0 echo Exit Value -1



STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.



Steps to Reproduce the Behavior
 In Microsoft Visual Studio .NET, create a new Visual C# Console Application project.  Add the following code to the Main function: Environment.Exit(1);   Press F5 to run the project under the debugger. The following appears in the Output window: 'DefaultDomain': Loaded 'c:\windows\microsoft.net\framework\v1.0.3705\mscorlib.dll', No symbols loaded. 'ConsoleApplication1': Loaded 'c:\srs\ConsoleApplication1\bin\Debug\ConsoleApplication1.exe', Symbols loaded. The program '[3840] ConsoleApplication1.exe' has exited with code 0 (0x0). 

