Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Process.get_ProcessName throws InvalidOperationException for 64-bit processes in Wow64 #20732

Open
madewokherd opened this issue Jan 9, 2021 · 1 comment · May be fixed by #20933
Open

Process.get_ProcessName throws InvalidOperationException for 64-bit processes in Wow64 #20732

madewokherd opened this issue Jan 9, 2021 · 1 comment · May be fixed by #20933

Comments

@madewokherd
Copy link
Contributor

Steps to Reproduce

  1. Install 32-bit Mono for Windows on a 64-bit machine.
  2. Run the following test program in 32-bit Mono.
using System;
using System.Diagnostics;

static class TestProcessNames
{
    public static int Main()
    {
		foreach (var p in Process.GetProcesses())
		{
			Console.WriteLine(p.Id);
			try
			{
				Console.WriteLine(p.ProcessName);
			}
			catch (InvalidOperationException)
			{
				if (p.HasExited)
					Console.WriteLine("[Process Exited]");
				else
					throw;
			}
		}
		return 0;
    }
}

Current Behavior

The program aborts with an InvalidOperationException.

Expected Behavior

The program prints the ID and name of each running process on the system. .NET Framework is able to do this, though it requires compiling the executable as 32-bit only to properly test.

On which platforms did you notice this

[ ] macOS
[ ] Linux
[x] Windows

Version Used:

6.12.0

Stacktrace

[ERROR] FATAL UNHANDLED EXCEPTION: System.InvalidOperationException: Process has exited or is inaccessible, so the requested information is not available.
  at System.Diagnostics.Process.get_ProcessName () [0x0002d] in <2833956e84fa47a69fb5c0a42a95869c>:0
  at (wrapper remoting-invoke-with-check) System.Diagnostics.Process.get_ProcessName()
  at TestProcessNames.Main () [0x0001d] in <1f41c1960fde40e2b33c1ef305d4af47>:0
@madewokherd
Copy link
Contributor Author

I suspect that the toolhelp API's aren't useful on wow64, and an alternative or fallback path may be needed. QueryFullProcessImageName may work.

MSDN documentation implies there is some sort of fallback: https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.processname

It's not clear to me what they might be doing that would truncate the name to 15 characters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant