12 [SuppressUnmanagedCodeSecurity]
16 private readonly
int nativeErrorCode;
18 private const int MaxAllowedBufferSize = 66560;
27 : this(
Marshal.GetLastWin32Error())
35 : this(error, GetErrorMessage(error))
46 nativeErrorCode = error;
53 : this(
Marshal.GetLastWin32Error(), message)
62 : base(message, innerException)
73 IntSecurity.UnmanagedCode.Demand();
74 nativeErrorCode = info.GetInt32(
"NativeErrorCode");
77 private static bool TryGetErrorMessage(
int error,
StringBuilder sb, out
string errorMsg)
80 if (Microsoft.Win32.SafeNativeMethods.FormatMessage(12800,
IntPtr.
Zero, (uint)error, 0, sb, sb.
Capacity + 1,
null) != 0)
83 for (num = sb.
Length; num > 0; num--)
86 if (c >
' ' && c !=
'.')
99 errorMsg =
"Unknown error (0x" +
Convert.ToString(error, 16) +
")";
104 private static string GetErrorMessage(
int error)
109 if (TryGetErrorMessage(error, stringBuilder, out
string errorMsg))
115 while (stringBuilder.
Capacity < 66560);
116 return "Unknown error (0x" +
Convert.ToString(error, 16) +
")";
131 info.AddValue(
"NativeErrorCode", nativeErrorCode);
132 base.GetObjectData(info, context);
Win32Exception(string message)
Initializes a new instance of the T:System.ComponentModel.Win32Exception class with the specified det...
Win32Exception(SerializationInfo info, StreamingContext context)
Initializes a new instance of the T:System.ComponentModel.Win32Exception class with the specified con...
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
Describes a set of security permissions applied to code. This class cannot be inherited.
Win32Exception()
Initializes a new instance of the T:System.ComponentModel.Win32Exception class with the last Win32 er...
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
Describes the source and destination of a given serialized stream, and provides an additional caller-...
SecurityAction
Specifies the security actions that can be performed using declarative security.
A cast or conversion operation, such as (SampleType)obj in C::or CType(obj, SampleType) in Visual Bas...
Throws an exception for a Win32 error code.
int Length
Gets or sets the length of the current T:System.Text.StringBuilder object.
A platform-specific type that is used to represent a pointer or a handle.
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
Win32Exception(int error, string message)
Initializes a new instance of the T:System.ComponentModel.Win32Exception class with the specified err...
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
Win32Exception(int error)
Initializes a new instance of the T:System.ComponentModel.Win32Exception class with the specified err...
Win32Exception(string message, Exception innerException)
Initializes a new instance of the T:System.ComponentModel.Win32Exception class with the specified det...
The base exception type for all COM interop exceptions and structured exception handling (SEH) except...
Allows an object to control its own serialization and deserialization.
int Capacity
Gets or sets the maximum number of characters that can be contained in the memory allocated by the cu...
Represents errors that occur during application execution.To browse the .NET Framework source code fo...
static readonly IntPtr Zero
A read-only field that represents a pointer or handle that has been initialized to zero.
override void GetObjectData(SerializationInfo info, StreamingContext context)
Sets the T:System.Runtime.Serialization.SerializationInfo object with the file name and line number a...
Specifies that the class can be serialized.
static int GetLastWin32Error()
Returns the error code returned by the last unmanaged function that was called using platform invoke ...
int NativeErrorCode
Gets the Win32 error code associated with this exception.
SecurityPermissionFlag
Specifies access flags for the security permission object.