PageRenderTime 52ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/Microsoft.Windows.Shell/Standard/ErrorCodes.cs

https://github.com/josephcooney/ILSpy
C# | 508 lines | 313 code | 41 blank | 154 comment | 28 complexity | 71e4db4d1dc63046cf15294da5fc9852 MD5 | raw file
  1. /**************************************************************************\
  2. Copyright Microsoft Corporation. All Rights Reserved.
  3. \**************************************************************************/
  4. namespace Standard
  5. {
  6. using System;
  7. using System.ComponentModel;
  8. using System.Diagnostics.CodeAnalysis;
  9. using System.Globalization;
  10. using System.Reflection;
  11. using System.Runtime.InteropServices;
  12. /// <summary>
  13. /// Wrapper for common Win32 status codes.
  14. /// </summary>
  15. [StructLayout(LayoutKind.Explicit)]
  16. internal struct Win32Error
  17. {
  18. [FieldOffset(0)]
  19. private readonly int _value;
  20. // NOTE: These public static field declarations are automatically
  21. // picked up by (HRESULT's) ToString through reflection.
  22. /// <summary>The operation completed successfully.</summary>
  23. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  24. public static readonly Win32Error ERROR_SUCCESS = new Win32Error(0);
  25. /// <summary>Incorrect function.</summary>
  26. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  27. public static readonly Win32Error ERROR_INVALID_FUNCTION = new Win32Error(1);
  28. /// <summary>The system cannot find the file specified.</summary>
  29. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  30. public static readonly Win32Error ERROR_FILE_NOT_FOUND = new Win32Error(2);
  31. /// <summary>The system cannot find the path specified.</summary>
  32. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  33. public static readonly Win32Error ERROR_PATH_NOT_FOUND = new Win32Error(3);
  34. /// <summary>The system cannot open the file.</summary>
  35. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  36. public static readonly Win32Error ERROR_TOO_MANY_OPEN_FILES = new Win32Error(4);
  37. /// <summary>Access is denied.</summary>
  38. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  39. public static readonly Win32Error ERROR_ACCESS_DENIED = new Win32Error(5);
  40. /// <summary>The handle is invalid.</summary>
  41. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  42. public static readonly Win32Error ERROR_INVALID_HANDLE = new Win32Error(6);
  43. /// <summary>Not enough storage is available to complete this operation.</summary>
  44. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  45. public static readonly Win32Error ERROR_OUTOFMEMORY = new Win32Error(14);
  46. /// <summary>There are no more files.</summary>
  47. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  48. public static readonly Win32Error ERROR_NO_MORE_FILES = new Win32Error(18);
  49. /// <summary>The process cannot access the file because it is being used by another process.</summary>
  50. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  51. public static readonly Win32Error ERROR_SHARING_VIOLATION = new Win32Error(32);
  52. /// <summary>The parameter is incorrect.</summary>
  53. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  54. public static readonly Win32Error ERROR_INVALID_PARAMETER = new Win32Error(87);
  55. /// <summary>The data area passed to a system call is too small.</summary>
  56. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  57. public static readonly Win32Error ERROR_INSUFFICIENT_BUFFER = new Win32Error(122);
  58. /// <summary>Cannot nest calls to LoadModule.</summary>
  59. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  60. public static readonly Win32Error ERROR_NESTING_NOT_ALLOWED = new Win32Error(215);
  61. /// <summary>Illegal operation attempted on a registry key that has been marked for deletion.</summary>
  62. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  63. public static readonly Win32Error ERROR_KEY_DELETED = new Win32Error(1018);
  64. /// <summary>Element not found.</summary>
  65. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  66. public static readonly Win32Error ERROR_NOT_FOUND = new Win32Error(1168);
  67. /// <summary>There was no match for the specified key in the index.</summary>
  68. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  69. public static readonly Win32Error ERROR_NO_MATCH = new Win32Error(1169);
  70. /// <summary>An invalid device was specified.</summary>
  71. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  72. public static readonly Win32Error ERROR_BAD_DEVICE = new Win32Error(1200);
  73. /// <summary>The operation was canceled by the user.</summary>
  74. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  75. public static readonly Win32Error ERROR_CANCELLED = new Win32Error(1223);
  76. /// <summary>The window class was already registered.</summary>
  77. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  78. public static readonly Win32Error ERROR_CLASS_ALREADY_EXISTS = new Win32Error(1410);
  79. /// <summary>The specified datatype is invalid.</summary>
  80. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  81. public static readonly Win32Error ERROR_INVALID_DATATYPE = new Win32Error(1804);
  82. /// <summary>
  83. /// Create a new Win32 error.
  84. /// </summary>
  85. /// <param name="i">The integer value of the error.</param>
  86. public Win32Error(int i)
  87. {
  88. _value = i;
  89. }
  90. /// <summary>Performs HRESULT_FROM_WIN32 conversion.</summary>
  91. /// <param name="error">The Win32 error being converted to an HRESULT.</param>
  92. /// <returns>The equivilent HRESULT value.</returns>
  93. public static explicit operator HRESULT(Win32Error error)
  94. {
  95. // #define __HRESULT_FROM_WIN32(x)
  96. // ((HRESULT)(x) <= 0 ? ((HRESULT)(x)) : ((HRESULT) (((x) & 0x0000FFFF) | (FACILITY_WIN32 << 16) | 0x80000000)))
  97. if (error._value <= 0)
  98. {
  99. return new HRESULT((uint)error._value);
  100. }
  101. return HRESULT.Make(true, Facility.Win32, error._value & 0x0000FFFF);
  102. }
  103. // Method version of the cast operation
  104. /// <summary>Performs HRESULT_FROM_WIN32 conversion.</summary>
  105. /// <param name="error">The Win32 error being converted to an HRESULT.</param>
  106. /// <returns>The equivilent HRESULT value.</returns>
  107. public HRESULT ToHRESULT()
  108. {
  109. return (HRESULT)this;
  110. }
  111. /// <summary>Performs the equivalent of Win32's GetLastError()</summary>
  112. /// <returns>A Win32Error instance with the result of the native GetLastError</returns>
  113. [SuppressMessage("Microsoft.Security", "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")]
  114. public static Win32Error GetLastError()
  115. {
  116. return new Win32Error(Marshal.GetLastWin32Error());
  117. }
  118. public override bool Equals(object obj)
  119. {
  120. try
  121. {
  122. return ((Win32Error)obj)._value == _value;
  123. }
  124. catch (InvalidCastException)
  125. {
  126. return false;
  127. }
  128. }
  129. public override int GetHashCode()
  130. {
  131. return _value.GetHashCode();
  132. }
  133. /// <summary>
  134. /// Compare two Win32 error codes for equality.
  135. /// </summary>
  136. /// <param name="errLeft">The first error code to compare.</param>
  137. /// <param name="errRight">The second error code to compare.</param>
  138. /// <returns>Whether the two error codes are the same.</returns>
  139. public static bool operator ==(Win32Error errLeft, Win32Error errRight)
  140. {
  141. return errLeft._value == errRight._value;
  142. }
  143. /// <summary>
  144. /// Compare two Win32 error codes for inequality.
  145. /// </summary>
  146. /// <param name="errLeft">The first error code to compare.</param>
  147. /// <param name="errRight">The second error code to compare.</param>
  148. /// <returns>Whether the two error codes are not the same.</returns>
  149. public static bool operator !=(Win32Error errLeft, Win32Error errRight)
  150. {
  151. return !(errLeft == errRight);
  152. }
  153. }
  154. internal enum Facility
  155. {
  156. /// <summary>FACILITY_NULL</summary>
  157. Null = 0,
  158. /// <summary>FACILITY_RPC</summary>
  159. Rpc = 1,
  160. /// <summary>FACILITY_DISPATCH</summary>
  161. Dispatch = 2,
  162. /// <summary>FACILITY_STORAGE</summary>
  163. Storage = 3,
  164. /// <summary>FACILITY_ITF</summary>
  165. Itf = 4,
  166. /// <summary>FACILITY_WIN32</summary>
  167. Win32 = 7,
  168. /// <summary>FACILITY_WINDOWS</summary>
  169. Windows = 8,
  170. /// <summary>FACILITY_CONTROL</summary>
  171. Control = 10,
  172. /// <summary>MSDN doced facility code for ESE errors.</summary>
  173. Ese = 0xE5E,
  174. /// <summary>FACILITY_WINCODEC (WIC)</summary>
  175. WinCodec = 0x898,
  176. }
  177. /// <summary>Wrapper for HRESULT status codes.</summary>
  178. [StructLayout(LayoutKind.Explicit)]
  179. internal struct HRESULT
  180. {
  181. [FieldOffset(0)]
  182. private readonly uint _value;
  183. // NOTE: These public static field declarations are automatically
  184. // picked up by ToString through reflection.
  185. /// <summary>S_OK</summary>
  186. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  187. public static readonly HRESULT S_OK = new HRESULT(0x00000000);
  188. /// <summary>S_FALSE</summary>
  189. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  190. public static readonly HRESULT S_FALSE = new HRESULT(0x00000001);
  191. /// <summary>E_PENDING</summary>
  192. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  193. public static readonly HRESULT E_PENDING = new HRESULT(0x8000000A);
  194. /// <summary>E_NOTIMPL</summary>
  195. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  196. public static readonly HRESULT E_NOTIMPL = new HRESULT(0x80004001);
  197. /// <summary>E_NOINTERFACE</summary>
  198. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  199. public static readonly HRESULT E_NOINTERFACE = new HRESULT(0x80004002);
  200. /// <summary>E_POINTER</summary>
  201. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  202. public static readonly HRESULT E_POINTER = new HRESULT(0x80004003);
  203. /// <summary>E_ABORT</summary>
  204. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  205. public static readonly HRESULT E_ABORT = new HRESULT(0x80004004);
  206. /// <summary>E_FAIL</summary>
  207. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  208. public static readonly HRESULT E_FAIL = new HRESULT(0x80004005);
  209. /// <summary>E_UNEXPECTED</summary>
  210. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  211. public static readonly HRESULT E_UNEXPECTED = new HRESULT(0x8000FFFF);
  212. /// <summary>STG_E_INVALIDFUNCTION</summary>
  213. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  214. public static readonly HRESULT STG_E_INVALIDFUNCTION = new HRESULT(0x80030001);
  215. /// <summary>REGDB_E_CLASSNOTREG</summary>
  216. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  217. public static readonly HRESULT REGDB_E_CLASSNOTREG = new HRESULT(0x80040154);
  218. /// <summary>DESTS_E_NO_MATCHING_ASSOC_HANDLER. Win7 internal error code for Jump Lists.</summary>
  219. /// <remarks>There is no Assoc Handler for the given item registered by the specified application.</remarks>
  220. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  221. public static readonly HRESULT DESTS_E_NO_MATCHING_ASSOC_HANDLER = new HRESULT(0x80040F03);
  222. /// <summary>DESTS_E_NORECDOCS. Win7 internal error code for Jump Lists.</summary>
  223. /// <remarks>The given item is excluded from the recent docs folder by the NoRecDocs bit on its registration.</remarks>
  224. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  225. public static readonly HRESULT DESTS_E_NORECDOCS = new HRESULT(0x80040F04);
  226. /// <summary>DESTS_E_NOTALLCLEARED. Win7 internal error code for Jump Lists.</summary>
  227. /// <remarks>Not all of the items were successfully cleared</remarks>
  228. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  229. public static readonly HRESULT DESTS_E_NOTALLCLEARED = new HRESULT(0x80040F05);
  230. /// <summary>E_ACCESSDENIED</summary>
  231. /// <remarks>Win32Error ERROR_ACCESS_DENIED.</remarks>
  232. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  233. public static readonly HRESULT E_ACCESSDENIED = new HRESULT(0x80070005);
  234. /// <summary>E_OUTOFMEMORY</summary>
  235. /// <remarks>Win32Error ERROR_OUTOFMEMORY.</remarks>
  236. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  237. public static readonly HRESULT E_OUTOFMEMORY = new HRESULT(0x8007000E);
  238. /// <summary>E_INVALIDARG</summary>
  239. /// <remarks>Win32Error ERROR_INVALID_PARAMETER.</remarks>
  240. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  241. public static readonly HRESULT E_INVALIDARG = new HRESULT(0x80070057);
  242. /// <summary>INTSAFE_E_ARITHMETIC_OVERFLOW</summary>
  243. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  244. public static readonly HRESULT INTSAFE_E_ARITHMETIC_OVERFLOW = new HRESULT(0x80070216);
  245. /// <summary>COR_E_OBJECTDISPOSED</summary>
  246. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  247. public static readonly HRESULT COR_E_OBJECTDISPOSED = new HRESULT(0x80131622);
  248. /// <summary>WC_E_GREATERTHAN</summary>
  249. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  250. public static readonly HRESULT WC_E_GREATERTHAN = new HRESULT(0xC00CEE23);
  251. /// <summary>WC_E_SYNTAX</summary>
  252. [SuppressMessage("Microsoft.Performance", "CA1823:AvoidUnusedPrivateFields")]
  253. public static readonly HRESULT WC_E_SYNTAX = new HRESULT(0xC00CEE2D);
  254. /// <summary>
  255. /// Create an HRESULT from an integer value.
  256. /// </summary>
  257. /// <param name="i"></param>
  258. public HRESULT(uint i)
  259. {
  260. _value = i;
  261. }
  262. public static HRESULT Make(bool severe, Facility facility, int code)
  263. {
  264. //#define MAKE_HRESULT(sev,fac,code) \
  265. // ((HRESULT) (((unsigned long)(sev)<<31) | ((unsigned long)(fac)<<16) | ((unsigned long)(code))) )
  266. // Severity has 1 bit reserved.
  267. // bitness is enforced by the boolean parameter.
  268. // Facility has 11 bits reserved (different than SCODES, which have 4 bits reserved)
  269. // MSDN documentation incorrectly uses 12 bits for the ESE facility (e5e), so go ahead and let that one slide.
  270. // And WIC also ignores it the documented size...
  271. Assert.Implies((int)facility != (int)((int)facility & 0x1FF), facility == Facility.Ese || facility == Facility.WinCodec);
  272. // Code has 4 bits reserved.
  273. Assert.AreEqual(code, code & 0xFFFF);
  274. return new HRESULT((uint)((severe ? (1 << 31) : 0) | ((int)facility << 16) | code));
  275. }
  276. /// <summary>
  277. /// retrieve HRESULT_FACILITY
  278. /// </summary>
  279. public Facility Facility
  280. {
  281. get
  282. {
  283. return GetFacility((int)_value);
  284. }
  285. }
  286. public static Facility GetFacility(int errorCode)
  287. {
  288. // #define HRESULT_FACILITY(hr) (((hr) >> 16) & 0x1fff)
  289. return (Facility)((errorCode >> 16) & 0x1fff);
  290. }
  291. /// <summary>
  292. /// retrieve HRESULT_CODE
  293. /// </summary>
  294. public int Code
  295. {
  296. get
  297. {
  298. return GetCode((int)_value);
  299. }
  300. }
  301. public static int GetCode(int error)
  302. {
  303. // #define HRESULT_CODE(hr) ((hr) & 0xFFFF)
  304. return (int)(error & 0xFFFF);
  305. }
  306. #region Object class override members
  307. /// <summary>
  308. /// Get a string representation of this HRESULT.
  309. /// </summary>
  310. /// <returns></returns>
  311. public override string ToString()
  312. {
  313. // Use reflection to try to name this HRESULT.
  314. // This is expensive, but if someone's ever printing HRESULT strings then
  315. // I think it's a fair guess that they're not in a performance critical area
  316. // (e.g. printing exception strings).
  317. // This is less error prone than trying to keep the list in the function.
  318. // To properly add an HRESULT's name to the ToString table, just add the HRESULT
  319. // like all the others above.
  320. //
  321. // CONSIDER: This data is static. It could be cached
  322. // after first usage for fast lookup since the keys are unique.
  323. //
  324. foreach (FieldInfo publicStaticField in typeof(HRESULT).GetFields(BindingFlags.Static | BindingFlags.Public))
  325. {
  326. if (publicStaticField.FieldType == typeof(HRESULT))
  327. {
  328. var hr = (HRESULT)publicStaticField.GetValue(null);
  329. if (hr == this)
  330. {
  331. return publicStaticField.Name;
  332. }
  333. }
  334. }
  335. // Try Win32 error codes also
  336. if (Facility == Facility.Win32)
  337. {
  338. foreach (FieldInfo publicStaticField in typeof(Win32Error).GetFields(BindingFlags.Static | BindingFlags.Public))
  339. {
  340. if (publicStaticField.FieldType == typeof(Win32Error))
  341. {
  342. var error = (Win32Error)publicStaticField.GetValue(null);
  343. if ((HRESULT)error == this)
  344. {
  345. return "HRESULT_FROM_WIN32(" + publicStaticField.Name + ")";
  346. }
  347. }
  348. }
  349. }
  350. // If there's no good name for this HRESULT,
  351. // return the string as readable hex (0x########) format.
  352. return string.Format(CultureInfo.InvariantCulture, "0x{0:X8}", _value);
  353. }
  354. public override bool Equals(object obj)
  355. {
  356. try
  357. {
  358. return ((HRESULT)obj)._value == _value;
  359. }
  360. catch (InvalidCastException)
  361. {
  362. return false;
  363. }
  364. }
  365. public override int GetHashCode()
  366. {
  367. return _value.GetHashCode();
  368. }
  369. #endregion
  370. public static bool operator ==(HRESULT hrLeft, HRESULT hrRight)
  371. {
  372. return hrLeft._value == hrRight._value;
  373. }
  374. public static bool operator !=(HRESULT hrLeft, HRESULT hrRight)
  375. {
  376. return !(hrLeft == hrRight);
  377. }
  378. public bool Succeeded
  379. {
  380. get { return (int)_value >= 0; }
  381. }
  382. public bool Failed
  383. {
  384. get { return (int)_value < 0; }
  385. }
  386. public void ThrowIfFailed()
  387. {
  388. ThrowIfFailed(null);
  389. }
  390. [
  391. SuppressMessage(
  392. "Microsoft.Usage",
  393. "CA2201:DoNotRaiseReservedExceptionTypes",
  394. Justification="Only recreating Exceptions that were already raised."),
  395. SuppressMessage(
  396. "Microsoft.Security",
  397. "CA2122:DoNotIndirectlyExposeMethodsWithLinkDemands")
  398. ]
  399. public void ThrowIfFailed(string message)
  400. {
  401. if (Failed)
  402. {
  403. if (string.IsNullOrEmpty(message))
  404. {
  405. message = ToString();
  406. }
  407. #if DEBUG
  408. else
  409. {
  410. message += " (" + ToString() + ")";
  411. }
  412. #endif
  413. // Wow. Reflection in a throw call. Later on this may turn out to have been a bad idea.
  414. // If you're throwing an exception I assume it's OK for me to take some time to give it back.
  415. // I want to convert the HRESULT to a more appropriate exception type than COMException.
  416. // Marshal.ThrowExceptionForHR does this for me, but the general call uses GetErrorInfo
  417. // if it's set, and then ignores the HRESULT that I've provided. This makes it so this
  418. // call works the first time but you get burned on the second. To avoid this, I use
  419. // the overload that explicitly ignores the IErrorInfo.
  420. // In addition, the function doesn't allow me to set the Message unless I go through
  421. // the process of implementing an IErrorInfo and then use that. There's no stock
  422. // implementations of IErrorInfo available and I don't think it's worth the maintenance
  423. // overhead of doing it, nor would it have significant value over this approach.
  424. Exception e = Marshal.GetExceptionForHR((int)_value, new IntPtr(-1));
  425. Assert.IsNotNull(e);
  426. // ArgumentNullException doesn't have the right constructor parameters,
  427. // (nor does Win32Exception...)
  428. // but E_POINTER gets mapped to NullReferenceException,
  429. // so I don't think it will ever matter.
  430. Assert.IsFalse(e is ArgumentNullException);
  431. // If we're not getting anything better than a COMException from Marshal,
  432. // then at least check the facility and attempt to do better ourselves.
  433. if (e.GetType() == typeof(COMException))
  434. {
  435. switch (Facility)
  436. {
  437. case Facility.Win32:
  438. e = new Win32Exception(Code, message);
  439. break;
  440. default:
  441. e = new COMException(message, (int)_value);
  442. break;
  443. }
  444. }
  445. else
  446. {
  447. ConstructorInfo cons = e.GetType().GetConstructor(new[] { typeof(string) });
  448. if (null != cons)
  449. {
  450. e = cons.Invoke(new object[] { message }) as Exception;
  451. Assert.IsNotNull(e);
  452. }
  453. }
  454. throw e;
  455. }
  456. }
  457. /// <summary>
  458. /// Convert the result of Win32 GetLastError() into a raised exception.
  459. /// </summary>
  460. public static void ThrowLastError()
  461. {
  462. ((HRESULT)Win32Error.GetLastError()).ThrowIfFailed();
  463. // Only expecting to call this when we're expecting a failed GetLastError()
  464. Assert.Fail();
  465. }
  466. }
  467. }