We started to replace custom CreateFileW pinvokes with File.OpenHandle() in PowerShell repository and was blocked because of the API limitations.
Currently there are strong argument validations:
|
if (mode < FileMode.CreateNew || mode > FileMode.Append) |
|
{ |
|
badArg = nameof(mode); |
|
} |
|
else if (access < FileAccess.Read || access > FileAccess.ReadWrite) |
|
{ |
|
badArg = nameof(access); |
|
} |
|
else if (tempshare < FileShare.None || tempshare > (FileShare.ReadWrite | FileShare.Delete)) |
|
{ |
|
badArg = nameof(share); |
|
} |
CreateFileW allows to use many flags for these parameters. Now they are blocked. In particular, we would like to have FILE_FLAG_POSIX_SEMANTICS, FILE_FLAG_OPEN_REPARSE_POINT, FILE_FLAG_BACKUP_SEMANTICS, FileAccess = 0 and so on.
What is the preferred way to solve this problem without using custom pinvoke?
Is it possible to remove these hard checks from the API so that we can use any flags with a simple cast?
The same question for another APIs like File.SetAttributes().
/cc @adamsitnik
We started to replace custom CreateFileW pinvokes with File.OpenHandle() in PowerShell repository and was blocked because of the API limitations.
Currently there are strong argument validations:
runtime/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/FileStreamHelpers.cs
Lines 62 to 73 in 1a37caf
CreateFileW allows to use many flags for these parameters. Now they are blocked. In particular, we would like to have FILE_FLAG_POSIX_SEMANTICS, FILE_FLAG_OPEN_REPARSE_POINT, FILE_FLAG_BACKUP_SEMANTICS, FileAccess = 0 and so on.
What is the preferred way to solve this problem without using custom pinvoke?
Is it possible to remove these hard checks from the API so that we can use any flags with a simple cast?
The same question for another APIs like File.SetAttributes().
/cc @adamsitnik