dotnet / dotnet/dotnet-api-docs

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

Open
#8,022 3 comments 0 reactions 0 assignees View on GitHub
area-System.Threading Pri3 untriaged
Dominant language
C#
Stars
949
Forks
1.7k
Avg merge
3d 27m
Merged PRs (30d)
49

Description

### 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_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.