Trying to access the new file system immediately after it is built fails with ERROR_INVALID_FUNCTION or ERROR_INVALID_PARAMETER (depending on type of access).
IMHO, Build by default should wait for the file system to be ready.
Workaround
const uint ERROR_INVALID_PARAMETER = 0x0057;
bool done = false;
while(!done) {
try {
mountDir.EnumerateFileSystemInfos().Any();
done = true;
} catch (IOException e)
when (GetWin32Error(e.HResult) == ERROR_INVALID_PARAMETER) {
await Task.Delay(TimeSpan.FromMilliseconds(25), cancel)
.ConfigureAwait(false);
}
}
static uint GetWin32Error(int hResult)
=> unchecked((uint)hResult) & 0xFFFF;
See also dokan-dev/dokan-dotnet#356