2 // System.ComponentModel.Win32Exception.cs
5 // Dick Porter (dick@ximian.com)
7 // (C) 2002 Ximian, Inc. http://www.ximian.com
8 // Copyright (C) 2005 Novell, Inc (http://www.novell.com)
10 // Permission is hereby granted, free of charge, to any person obtaining
11 // a copy of this software and associated documentation files (the
12 // "Software"), to deal in the Software without restriction, including
13 // without limitation the rights to use, copy, modify, merge, publish,
14 // distribute, sublicense, and/or sell copies of the Software, and to
15 // permit persons to whom the Software is furnished to do so, subject to
16 // the following conditions:
18 // The above copyright notice and this permission notice shall be
19 // included in all copies or substantial portions of the Software.
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
23 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
25 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
26 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
27 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30 using System.Security;
31 using System.Security.Permissions;
32 using System.Runtime.InteropServices;
33 using System.Runtime.Serialization;
34 using System.Collections;
35 using System.Globalization;
36 using System.Runtime.CompilerServices;
38 namespace System.ComponentModel
40 [Serializable, SuppressUnmanagedCodeSecurity]
41 public class Win32Exception : ExternalException
43 private int native_error_code;
45 // [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
47 [MonoNotSupported("")]
49 public Win32Exception ()
50 : base (W32ErrorMessage (Marshal.GetLastWin32Error ()))
52 native_error_code = Marshal.GetLastWin32Error ();
55 // [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
56 public Win32Exception (int error)
57 : base (W32ErrorMessage (error))
59 native_error_code = error;
62 // [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
63 public Win32Exception (int error, string message)
66 native_error_code = error;
68 [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
70 [MonoNotSupported ("")]
72 public Win32Exception (string message)
75 native_error_code = Marshal.GetLastWin32Error ();
79 [MonoNotSupported ("")]
81 [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
82 public Win32Exception (string message, Exception innerException)
83 : base (message, innerException)
85 native_error_code = Marshal.GetLastWin32Error ();
88 protected Win32Exception(SerializationInfo info,
89 StreamingContext context)
90 : base (info, context) {
92 native_error_code = info.GetInt32 ("NativeErrorCode");
95 public int NativeErrorCode {
97 return(native_error_code);
101 [SecurityPermission (SecurityAction.Demand, SerializationFormatter = true)]
102 public override void GetObjectData(SerializationInfo info, StreamingContext context)
105 throw new ArgumentNullException ("info");
107 info.AddValue ("NativeErrorCode", native_error_code);
108 base.GetObjectData (info, context);
111 [MethodImplAttribute (MethodImplOptions.InternalCall)]
112 internal static extern string W32ErrorMessage (int error_code);