Skip to content

Update SafeProcessHandle.Unix.cs#128416

Open
Neo-vortex wants to merge 1 commit into
dotnet:mainfrom
Neo-vortex:fix-misleading-error
Open

Update SafeProcessHandle.Unix.cs#128416
Neo-vortex wants to merge 1 commit into
dotnet:mainfrom
Neo-vortex:fix-misleading-error

Conversation

@Neo-vortex

Copy link
Copy Markdown
Contributor

fix: Throw appropriate exception when no shell-open utility is found

fixes : #96565

Problem

Process.GetPathToOpenFile() can return null when no shell-open utility (e.g. xdg-open, open) is found on the system. The return value was previously used without a null check, which could lead to a null reference further down the call path.

Changes

Added a null check on the return value of GetPathToOpenFile() that throws a Win32Exception with ERROR_NO_ASSOCIATION when no utility is found.

filename = Process.GetPathToOpenFile()
    ?? throw new Win32Exception(Interop.Errors.ERROR_NO_ASSOCIATION);

@adamsitnik adamsitnik left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Neo-vortex thank you for your contribution.

Could you please add a test similar to this one? Then on distros where xdg-open and similar are not available (IIRC one would be Ubuntu run via WSL), we can test the change.

Thanks!

@adamsitnik adamsitnik added the needs-author-action An issue or pull request that requires more info or actions from the author. label Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.Diagnostics.Process community-contribution Indicates that the PR has been added by a community member needs-author-action An issue or pull request that requires more info or actions from the author.

Projects

None yet

2 participants