From f3a86db1ea4001ddfec0c152612a78da138afe19 Mon Sep 17 00:00:00 2001 From: Simon Nattress Date: Tue, 27 Feb 2018 16:00:09 -0800 Subject: [PATCH] Fix GetAddrInfoExSupportsOverlapped UAP build break `System.Net.NameResolutionPal.GetAddrInfoExSupportsOverlapped` uses LoadLibraryExW which is not compatible with UAP (which only supports LoadLibrary of DLLs within a container). Refactor the helper so UAP returns false. --- .../src/System.Net.NameResolution.csproj | 4 ++- .../NameResolutionPal.Windows.NetCoreApp.cs | 25 +++++++++++++++++++ .../Net/NameResolutionPal.Windows.Uap.cs | 15 +++++++++++ .../System/Net/NameResolutionPal.Windows.cs | 15 +---------- 4 files changed, 44 insertions(+), 15 deletions(-) create mode 100644 src/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.NetCoreApp.cs create mode 100644 src/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.Uap.cs diff --git a/src/System.Net.NameResolution/src/System.Net.NameResolution.csproj b/src/System.Net.NameResolution/src/System.Net.NameResolution.csproj index 8268964df020..1ebd2872db81 100644 --- a/src/System.Net.NameResolution/src/System.Net.NameResolution.csproj +++ b/src/System.Net.NameResolution/src/System.Net.NameResolution.csproj @@ -54,6 +54,8 @@ + + Common\System\Net\ContextAwareResult.Windows.cs @@ -132,7 +134,7 @@ Interop\Windows\Kernel32\Interop.GetProcAddress.cs - + Interop\Windows\Kernel32\Interop.LoadLibraryEx.cs diff --git a/src/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.NetCoreApp.cs b/src/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.NetCoreApp.cs new file mode 100644 index 000000000000..da3d02a19180 --- /dev/null +++ b/src/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.NetCoreApp.cs @@ -0,0 +1,25 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +using Microsoft.Win32.SafeHandles; + +namespace System.Net +{ + internal static partial class NameResolutionPal + { + + private static bool GetAddrInfoExSupportsOverlapped() + { + using (SafeLibraryHandle libHandle = Interop.Kernel32.LoadLibraryExW(Interop.Libraries.Ws2_32, IntPtr.Zero, Interop.Kernel32.LOAD_LIBRARY_SEARCH_SYSTEM32)) + { + if (libHandle.IsInvalid) + return false; + + // We can't just check that 'GetAddrInfoEx' exists, because it existed before supporting overlapped. + // The existance of 'GetAddrInfoExCancel' indicates that overlapped is supported. + return Interop.Kernel32.GetProcAddress(libHandle, Interop.Winsock.GetAddrInfoExCancelFunctionName) != IntPtr.Zero; + } + } + } +} diff --git a/src/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.Uap.cs b/src/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.Uap.cs new file mode 100644 index 000000000000..dbe26d12a70d --- /dev/null +++ b/src/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.Uap.cs @@ -0,0 +1,15 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. + +namespace System.Net +{ + internal static partial class NameResolutionPal + { + + private static bool GetAddrInfoExSupportsOverlapped() + { + return false; + } + } +} diff --git a/src/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.cs b/src/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.cs index 33538ac298d8..ed6216eca94c 100644 --- a/src/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.cs +++ b/src/System.Net.NameResolution/src/System/Net/NameResolutionPal.Windows.cs @@ -13,7 +13,7 @@ namespace System.Net { - internal static class NameResolutionPal + internal static partial class NameResolutionPal { // // used by GetHostName() to preallocate a buffer for the call to gethostname. @@ -339,19 +339,6 @@ public static void EnsureSocketsAreInitialized() } } - private static bool GetAddrInfoExSupportsOverlapped() - { - using (SafeLibraryHandle libHandle = Interop.Kernel32.LoadLibraryExW(Interop.Libraries.Ws2_32, IntPtr.Zero, Interop.Kernel32.LOAD_LIBRARY_SEARCH_SYSTEM32)) - { - if (libHandle.IsInvalid) - return false; - - // We can't just check that 'GetAddrInfoEx' exists, because it existed before supporting overlapped. - // The existance of 'GetAddrInfoExCancel' indicates that overlapped is supported. - return Interop.Kernel32.GetProcAddress(libHandle, Interop.Winsock.GetAddrInfoExCancelFunctionName) != IntPtr.Zero; - } - } - public static unsafe void GetAddrInfoAsync(DnsResolveAsyncResult asyncResult) { GetAddrInfoExContext* context = GetAddrInfoExContext.AllocateContext();