Does .NET Standard normalize HResult values across every platform it supports?

后端 未结 1 398
无人及你
无人及你 2020-12-19 04:49

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         


        
相关标签:
1条回答
  • 2020-12-19 04:59

    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

    0 讨论(0)
提交回复
热议问题