From 4b398b3f73817be49fcc473e202f1abd589c08dd Mon Sep 17 00:00:00 2001 From: David Hall Date: Sat, 25 May 2024 21:36:16 -0600 Subject: [PATCH] Fixed #467 where IErrorHandler types threw error on ToString method after 4.0.1. --- PInvoke/Shared/ErrorHelper.cs | 2 +- UnitTests/PInvoke/Shared/WinError/Win32ErrorTests.cs | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/PInvoke/Shared/ErrorHelper.cs b/PInvoke/Shared/ErrorHelper.cs index 8369ed97..6127f16e 100644 --- a/PInvoke/Shared/ErrorHelper.cs +++ b/PInvoke/Shared/ErrorHelper.cs @@ -27,7 +27,7 @@ public static class ErrorHelper { if (!lookupHelpers.TryGetValue(typeof(TType), out var lookupFunc)) lookupFunc = FormatMessage; - return lookupFunc(id.ToUInt32(null), lib ?? StaticFieldValueHash.GetFieldLib(id)); + return lookupFunc(unchecked((uint)id.ToInt64(null)), lib ?? StaticFieldValueHash.GetFieldLib(id)); } /// Formats the message. diff --git a/UnitTests/PInvoke/Shared/WinError/Win32ErrorTests.cs b/UnitTests/PInvoke/Shared/WinError/Win32ErrorTests.cs index afaeb789..8a2c92c2 100644 --- a/UnitTests/PInvoke/Shared/WinError/Win32ErrorTests.cs +++ b/UnitTests/PInvoke/Shared/WinError/Win32ErrorTests.cs @@ -121,6 +121,12 @@ public class Win32ErrorTests [TestCase(0x00990003U, "0x00990003")] public void ToStringTest(uint c, string val) => Assert.That(new Win32Error(c).ToString(), Does.StartWith(val)); + [Test] + public void ToStringHRESULTTest() + { + Assert.That(new Win32Error(Win32Error.ERROR_CLOUD_FILE_NOT_UNDER_SYNC_ROOT).ToHRESULT().ToString(), Does.StartWith("HRESULT_FROM_WIN32(ERROR_CLOUD_FILE_NOT_UNDER_SYNC_ROOT")); + } + [Test] public void TypeConverterTest() {