From dfe09d384207a815efb8cc2f2176bfe1a6ae13ba Mon Sep 17 00:00:00 2001 From: dengel Date: Thu, 26 Sep 2019 14:22:20 -0700 Subject: [PATCH] Get last error when LoadLibrary fails --- .../src/Microsoft/Data/Interop/SNINativeMethodWrapper.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/Interop/SNINativeMethodWrapper.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/Interop/SNINativeMethodWrapper.cs index e2d947cab9..7561ced63a 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/Interop/SNINativeMethodWrapper.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/Interop/SNINativeMethodWrapper.cs @@ -61,7 +61,8 @@ static SNINativeMethodWrapper() IntPtr pDll = LoadLibrary(localFolder + subfolder + SNI); if (pDll == IntPtr.Zero) { - throw new System.ComponentModel.Win32Exception("Failed to load " + localFolder + subfolder + SNI); + throw new System.ComponentModel.Win32Exception("Failed to load " + localFolder + subfolder + SNI, + new System.ComponentModel.Win32Exception(Marshal.GetLastWin32Error())); } } @@ -389,7 +390,7 @@ internal struct SNI_Error #endregion #region DLL Imports - [DllImport("kernel32.dll")] + [DllImport("kernel32.dll", SetLastError=true)] public static extern IntPtr LoadLibrary(string dllToLoad); [DllImport("secur32.dll", ExactSpelling = true, SetLastError = true)]