Skip to content

Docs should specify that names of Mutex, AutoResetEvent, and Semaphores may not contain '/' when running on Unix  #8022

Open
@Whiletru3

Description

@Whiletru3

Description

I try to use System.Threading Mutex(bool initiallyOwned, string? name, out bool createdNew) on macOS in a net6 project.
The name I use contain a slash ("/"). On windows I have no issue with it, but on macOS, I have an exception :

System.IO.IOException: The filename, directory name, or volume label syntax is incorrect. : '6dace8f3-282b-4b6e-ab0b-99026a8fb613/c8cf2963-3b12-4537-8a44-4aac2dad98dc'
   at System.Threading.Mutex.CreateMutexCore(Boolean initiallyOwned, String name, Boolean& createdNew)
   at System.Threading.Mutex..ctor(Boolean initiallyOwned, String name, Boolean& createdNew)

There are no such of restriction in the documentation, only the backslash is reserved.

https://docs.microsoft.com/en-us/dotnet/api/system.threading.mutex?view=net-6.0

The backslash (\) is a reserved character in a mutex name. Don't use a backslash (\) in a mutex name except as specified in the note on using mutexes in terminal server sessions. Otherwise, a [DirectoryNotFoundException](https://docs.microsoft.com/en-us/dotnet/api/system.io.directorynotfoundexception?view=net-6.0) may be thrown, even though the name of the mutex represents an existing file.

It could be good to add the / as reserved.

Reproduction Steps

Mutex mutex = new Mutex(true, "1234/5678", out var isCreatedNew);

Expected behavior

no exception or invalid name

Actual behavior

launch an exception

Regression?

No response

Known Workarounds

replace / with another character

Configuration

.net6 Mac 12.3 x64

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Pri3Indicates issues/PRs that are low priorityarea-System.ThreadinguntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions