As a drop-in replacement for System.IO.File, the method overloads for File.OpenRead (and File.OpenReadTransacted) should use FileShare.Read. However, they don't.
The AlphaFS File.OpenRead/OpenReadTransacted implementations call File.Open/OpenTransacted methods without specifying an FileShare.Read argument, which means the file is opened using FileShare.None).
The following example code using System.IO.File.OpenRead twice with the same file executes successfully without errors.
using (var s1 = System.IO.File.OpenRead(filePath))
{
using (var s2 = System.IO.File.OpenRead(filePath)) // <--- works!
{
}
}
However, using the same example code with AlphaFS will not work:
using (var s1 = Alphaleonis.Win32.Filesystem.File.OpenRead(filePath))
{
using (var s2 = Alphaleonis.Win32.Filesystem.File.OpenRead(filePath)) // <--- IOException
{
}
}
The second (nested) call of Alphaleonis.Win32.Filesystem.File.OpenRead will throw an IOException, due to the first (outer) File.OpenRead call not using FileShare.Read as expected.
As a drop-in replacement for System.IO.File, the method overloads for File.OpenRead (and File.OpenReadTransacted) should use FileShare.Read. However, they don't.
The AlphaFS File.OpenRead/OpenReadTransacted implementations call File.Open/OpenTransacted methods without specifying an FileShare.Read argument, which means the file is opened using FileShare.None).
The following example code using System.IO.File.OpenRead twice with the same file executes successfully without errors.
However, using the same example code with AlphaFS will not work:
The second (nested) call of Alphaleonis.Win32.Filesystem.File.OpenRead will throw an IOException, due to the first (outer) File.OpenRead call not using FileShare.Read as expected.