I am creating a simple function that creates a random file. To be thread safe, it creates the file in a retry loop and if the file exists it tries again.
whi
Exception.HResult values are not standardized across platforms.
For I/O errors, .NET Core will return platform specific error code as HResult. The value of HResult property for file already exist in your example is going be 17 on Linux, and it may be different value for other Unix systems.
The relevant code that maps IO errors to exceptions on Unix is here: https://github.com/dotnet/corefx/blob/master/src/Common/src/Interop/Unix/Interop.IOErrors.cs