8 internal static class __Error
10 internal const int ERROR_FILE_NOT_FOUND = 2;
12 internal const int ERROR_PATH_NOT_FOUND = 3;
14 internal const int ERROR_ACCESS_DENIED = 5;
16 internal const int ERROR_INVALID_PARAMETER = 87;
20 throw new EndOfStreamException(Environment.GetResourceString(
"IO.EOF_ReadBeyondEOF"));
23 internal static void FileNotOpen()
25 throw new ObjectDisposedException(
null, Environment.GetResourceString(
"ObjectDisposed_FileClosed"));
28 internal static void StreamIsClosed()
30 throw new ObjectDisposedException(
null, Environment.GetResourceString(
"ObjectDisposed_StreamClosed"));
33 internal static void MemoryStreamNotExpandable()
35 throw new NotSupportedException(Environment.GetResourceString(
"NotSupported_MemStreamNotExpandable"));
38 internal static void ReaderClosed()
40 throw new ObjectDisposedException(
null, Environment.GetResourceString(
"ObjectDisposed_ReaderClosed"));
43 internal static void ReadNotSupported()
45 throw new NotSupportedException(Environment.GetResourceString(
"NotSupported_UnreadableStream"));
48 internal static void SeekNotSupported()
50 throw new NotSupportedException(Environment.GetResourceString(
"NotSupported_UnseekableStream"));
53 internal static void WrongAsyncResult()
55 throw new ArgumentException(Environment.GetResourceString(
"Arg_WrongAsyncResult"));
58 internal static void EndReadCalledTwice()
60 throw new ArgumentException(Environment.GetResourceString(
"InvalidOperation_EndReadCalledMultiple"));
63 internal static void EndWriteCalledTwice()
65 throw new ArgumentException(Environment.GetResourceString(
"InvalidOperation_EndWriteCalledMultiple"));
69 internal static string GetDisplayablePath(
string path,
bool isInvalidPath)
71 if (
string.IsNullOrEmpty(path))
79 if (PathInternal.IsPartiallyQualified(path) && !isInvalidPath)
95 catch (ArgumentException)
98 catch (NotSupportedException)
103 path = ((!
Path.IsDirectorySeparator(path[path.Length - 1])) ?
Path.GetFileName(path) : Environment.GetResourceString(
"IO.IO_NoPermissionToDirectoryName"));
108 [SecuritySafeCritical]
109 internal static void WinIOError()
112 WinIOError(lastWin32Error,
string.Empty);
116 internal static void WinIOError(
int errorCode,
string maybeFullPath)
118 bool isInvalidPath = errorCode == 123 || errorCode == 161;
119 string displayablePath = GetDisplayablePath(maybeFullPath, isInvalidPath);
123 if (displayablePath.Length == 0)
125 throw new FileNotFoundException(Environment.GetResourceString(
"IO.FileNotFound"));
127 throw new FileNotFoundException(Environment.GetResourceString(
"IO.FileNotFound_FileName", displayablePath), displayablePath);
129 if (displayablePath.Length == 0)
131 throw new DirectoryNotFoundException(Environment.GetResourceString(
"IO.PathNotFound_NoPathName"));
133 throw new DirectoryNotFoundException(Environment.GetResourceString(
"IO.PathNotFound_Path", displayablePath));
135 if (displayablePath.Length == 0)
137 throw new UnauthorizedAccessException(Environment.GetResourceString(
"UnauthorizedAccess_IODenied_NoPathName"));
139 throw new UnauthorizedAccessException(Environment.GetResourceString(
"UnauthorizedAccess_IODenied_Path", displayablePath));
141 if (displayablePath.Length != 0)
143 throw new IOException(Environment.GetResourceString(
"IO.IO_AlreadyExists_Name", displayablePath), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath);
147 throw new PathTooLongException(Environment.GetResourceString(
"IO.PathTooLong"));
149 throw new DriveNotFoundException(Environment.GetResourceString(
"IO.DriveNotFound_Drive", displayablePath));
151 throw new IOException(Win32Native.GetMessage(errorCode), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath);
153 if (displayablePath.Length == 0)
155 throw new IOException(Environment.GetResourceString(
"IO.IO_SharingViolation_NoFileName"), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath);
157 throw new IOException(Environment.GetResourceString(
"IO.IO_SharingViolation_File", displayablePath), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath);
159 if (displayablePath.Length != 0)
161 throw new IOException(Environment.GetResourceString(
"IO.IO_FileExists_Name", displayablePath), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath);
165 throw new OperationCanceledException();
167 throw new IOException(Win32Native.GetMessage(errorCode), Win32Native.MakeHRFromErrorCode(errorCode), maybeFullPath);
170 [SecuritySafeCritical]
171 internal static void WinIODriveError(
string driveName)
174 WinIODriveError(driveName, lastWin32Error);
178 internal static void WinIODriveError(
string driveName,
int errorCode)
180 if (errorCode == 3 || errorCode == 15)
182 throw new DriveNotFoundException(Environment.GetResourceString(
"IO.DriveNotFound_Drive", driveName));
184 WinIOError(errorCode, driveName);
187 internal static void WriteNotSupported()
189 throw new NotSupportedException(Environment.GetResourceString(
"NotSupported_UnwritableStream"));
192 internal static void WriterClosed()
194 throw new ObjectDisposedException(
null, Environment.GetResourceString(
"ObjectDisposed_WriterClosed"));
FileIOPermissionAccess
Specifies the type of file access requested.
The end of the file has been reached successfully.
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
Controls the ability to access files and folders. This class cannot be inherited.
static int GetLastWin32Error()
Returns the error code returned by the last unmanaged function that was called using platform invoke ...
The P:System.Uri.LocalPath data.
The exception that is thrown when a security error is detected.