From a820ca1c4f9cb5892331e2624d3999c39161fe2a Mon Sep 17 00:00:00 2001 From: Vitek Karas Date: Fri, 18 Sep 2020 08:24:14 -0700 Subject: [PATCH] Adapt to new behavior of nano server in resource updater (#42444) In recent builds of nano server BeginUpdateResource will return ERROR_CALL_NOT_IMPLEMENTED. ResourceUpdater needs to adapt to provide a good error experience. Without this change the code still fails, but with a much less friendly error. --- src/installer/managed/Microsoft.NET.HostModel/ResourceUpdater.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/installer/managed/Microsoft.NET.HostModel/ResourceUpdater.cs b/src/installer/managed/Microsoft.NET.HostModel/ResourceUpdater.cs index b0cc571..04b6b8a 100644 --- a/src/installer/managed/Microsoft.NET.HostModel/ResourceUpdater.cs +++ b/src/installer/managed/Microsoft.NET.HostModel/ResourceUpdater.cs @@ -138,6 +138,8 @@ namespace Microsoft.NET.HostModel [DllImport(nameof(Kernel32), SetLastError=true)] public static extern uint SizeofResource(IntPtr hModule, IntPtr hResInfo); + + public const int ERROR_CALL_NOT_IMPLEMENTED = 0x78; } /// @@ -183,9 +185,13 @@ namespace Microsoft.NET.HostModel { // On Nano Server 1709+, `BeginUpdateResource` is exported but returns a null handle with a zero error // Try to call `BeginUpdateResource` with an invalid parameter; the error should be non-zero if supported + // On Nano Server 20213, `BeginUpdateResource` fails with ERROR_CALL_NOT_IMPLEMENTED using (var handle = Kernel32.BeginUpdateResource("", false)) { - if (handle.IsInvalid && Marshal.GetLastWin32Error() == 0) + int lastWin32Error = Marshal.GetLastWin32Error(); + + if ((handle.IsInvalid && lastWin32Error == 0) || + lastWin32Error == Kernel32.ERROR_CALL_NOT_IMPLEMENTED) { return false; } -- 2.7.4