[process] Fix Process.GetProcessesByName (#4351)
authorLudovic Henry <ludovic@xamarin.com>
Thu, 9 Feb 2017 03:29:03 +0000 (22:29 -0500)
committerGitHub <noreply@github.com>
Thu, 9 Feb 2017 03:29:03 +0000 (22:29 -0500)
commit41fced547f724e3eb19a7e4c6ac88b14e702e82c
tree6b0960d0ef80be1034e47ecc888d6c2d6f218379
parent9780c4d801a7670aa2243e7bd709659996d2147f
[process] Fix Process.GetProcessesByName (#4351)

To get a process by name, we need to access the other process ProcessName, but it can fails on non-win32 platforms. This failure wouldn't be caught in the referencesource implementation trigerring this bug.

The exception we would observe would be:
 Unhandled Exception:
 System.InvalidOperationException: Process has exited, so the requested information is not available.
   at System.Diagnostics.Process.get_ProcessName () [0x0002d] in /Users/alexander/dev/mono/mcs/class/System/System.Diagnostics/Process.cs:336
   at (wrapper remoting-invoke-with-check) System.Diagnostics.Process:get_ProcessName ()
   at Program.Main (System.String[] args) [0x0003b] in <9c838a66cdc44c81b38c974edcc9c029>:0
 [ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidOperationException: Process has exited, so the requested information is not available.
   at System.Diagnostics.Process.get_ProcessName () [0x0002d] in /Users/alexander/dev/mono/mcs/class/System/System.Diagnostics/Process.cs:336
   at (wrapper remoting-invoke-with-check) System.Diagnostics.Process:get_ProcessName ()
   at Program.Main (System.String[] args) [0x0003b] in <9c838a66cdc44c81b38c974edcc9c029>:0

Fixes bug https://bugzilla.xamarin.com/show_bug.cgi?id=52345
mcs/class/System/System.Diagnostics/Process.cs
mcs/class/System/Test/System.Diagnostics/ProcessTest.cs
mcs/class/referencesource/System/services/monitoring/system/diagnosticts/Process.cs