Bug 43026 - Process.ExitCode throws an exception if accessed inside the `Exited` event
Summary: Process.ExitCode throws an exception if accessed inside the `Exited` event
Alias: None
Product: Runtime
Classification: Mono
Component: io-layer ()
Version: 4.7.X
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Ludovic Henry
Depends on:
Reported: 2016-08-03 09:43 UTC by Alan McGovern
Modified: 2016-09-14 01:05 UTC (History)
4 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Alan McGovern 2016-08-03 09:43:43 UTC
WE've attached an event handler to the `Process.Exited` event and are accessing the `ExitCode` property to see why the process exited. This is throwing the following exception `System.InvalidOperationException: Process must exit before requested information can be determined`. That seems weird :p

Mono 4.7.0 (master/d3582e9) (64-bit)

Comment 2 Rodrigo Kumpera 2016-09-14 01:05:30 UTC
This looks to have being recently fixed.

I tried the following with 104fd9c63861e391e502942643863385417c251a and it worked.

using System;
using System.Diagnostics;
using System.Threading;

public static class Program
	public static void Main()
	    var p = new Process();
		p.StartInfo.FileName = "true";
		p.EnableRaisingEvents = true;
		p.Exited += (a,b) => {
			Console.WriteLine ("first done");
			var pp = (Process)a;
			Console.WriteLine ("exited due to {0}", pp.ExitCode);
		p.Start ();
		p.WaitForExit ();
		Console.WriteLine ("second done");