Skip to content

Process properties throw Win32Exceptions instead of documented InvalidOperationException #125741

Description

@drauch

Description

You are not allowed to get some properties on the Process class (at least on Linux) after the process has exited. Reasoning (for the StartTime property) can be found here: #18540 . However, for Linux the correct exception should be documented on https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.starttime?view=net-10.0

It is already weird that StartTime throws a _Win32_Exception on Linux if the process has already exited, but it is at least somewhat symmetric to Windows.

However, I realized the same problem exists for other properties as well where this behavior is not documented at all, e.g., TotalProcessorTime throws a Win32Exception which it does not do on Windows (and the exception type is not even documented).

Please bring this in order, either documentation-wise or better implementation wise (Win32Exception is very weird on non Windows platforms).

Best regards,
D.R.

Reproduction Steps

Call Process.TotalProcessorTime on Linux after a process has exited => throws undocumented Win32Exception.

Expected behavior

According to docs: should not throw at all.

Actual behavior

Throws Win32Exception.

Regression?

No response

Known Workarounds

No response

Configuration

No response

Other information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions