Type of issue
Missing information
Description
In the File.ReadAllText method description there's an exception listed:
UnauthorizedAccessException
path specified a file that is read-only.
Without further explanation to this exception it is very confusing to the reader: It implies that the File.ReadAllText cannot read from files that are read-only.
Looking at the .NET source code, however, File.ReadAllText opens files with arguments FileMode.Open, FileAccess.Read, FileShare.Read. So, it's perfectly legal – and reasonable, if I may say so – to read from read-only files using File.ReadAllText.
In the documentation, please
- elaborate on the fact that files are read with above mentioned file access arguments,
- elaborate on the (obscure) special case causing above mentioned UnauthorizedAccessException to be thrown.
Page URL
https://learn.microsoft.com/en-us/dotnet/api/system.io.file.readalltext?view=net-9.0&devlangs=csharp&f1url=%3FappId%3DDev17IDEF1%26l%3DDE-DE%26k%3Dk(System.IO.File.ReadAllText)%3Bk(DevLang-csharp)%26rd%3Dtrue
Content source URL
https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.IO/File.xml
Document Version Independent Id
b97f3644-3681-9fd1-a7b5-52e994db2233
Platform Id
01172106-1daf-bc5a-5bdc-75ec5f5ad0f5
Article author
@dotnet-bot