BUG: Incorrect Exit Code Displayed in Output Window When Application Run Under Debugger (320165)



The information in this article applies to:

  • Microsoft Visual C# .NET (2002)
  • Microsoft Visual C# .NET (2003)

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.

MORE INFORMATION

Steps to Reproduce the Behavior

  1. In Microsoft Visual Studio .NET, create a new Visual C# Console Application project.
  2. Add the following code to the Main function:
    Environment.Exit(1);
    					
  3. 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).
    					

REFERENCES

For additional information about testing ERRORLEVELs, click the article number below to view the article in the Microsoft Knowledge Base:

39585 Correct Testing Precedence of Batch File ERRORLEVELs


Modification Type:MinorLast Reviewed:5/28/2003
Keywords:kbbug KB320165