runtime: macOS: undocumented errorCode for IOException thrown on FileInfo(path).Open(FileMode.Open)

Issue Title

macOS: undocumented errorCode for IOException thrown on FileInfo(path).Open(FileMode.Open)

General

Environment: MacOS Mojave 14.3 .NetCoreApp-v2.1

when using FileInfo(pathname).Open(FileMode.Open)) and an IOException is thrown, errorCode reported is 35 regardless if Marshal.GetHRForException(e) or e.HResult is used to retrieve the error code. error code 35 is undocumented in your documentation:

https://docs.microsoft.com/en-us/windows/desktop/debug/system-error-codes--0-499-

The mono implementation .NETFoundation 462 does the more correct thing and report an error code 32. This error code is reasonable error for the situation in a macOS environment (process can’t be shared because it’s being used by another process).

BUT if 35 is actually the right error code, Microsoft needs to document this as its undocumented.

Sample code:

             try
             {
                using (new FileInfo(Path.GetTempFileName()).Open(FileMode.Open))
                 {
                     return false;
                 }
             }
             catch (IOException e)
             {
                 // mono .NETFramework 462 is value 32, .NETCore-v2.1 is 35
                    var errorCode = Marshal.GetHRForException(e) & ((1 << 16) - 1);
                 
                 // .NETCore-v2.1 value is 35, mono .NETFramework 462 is some huge negative number
                var errorCode2 = e.HResult;

             }

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 16 (7 by maintainers)

Most upvoted comments

I find it a bit amusing that I’m a Linux guy asking for Windows functionality for the sake of cross-platform behavior 😃