diff --git a/src/libraries/Common/src/Interop/FreeBSD/Interop.Libraries.cs b/src/libraries/Common/src/Interop/FreeBSD/Interop.Libraries.cs index dc12091e1c02c..59b869c16510c 100644 --- a/src/libraries/Common/src/Interop/FreeBSD/Interop.Libraries.cs +++ b/src/libraries/Common/src/Interop/FreeBSD/Interop.Libraries.cs @@ -5,7 +5,6 @@ internal static partial class Interop { internal static partial class Libraries { - internal const string Odbc32 = "libodbc.so.2"; internal const string MsQuic = "libmsquic.so"; } } diff --git a/src/libraries/Common/src/Interop/Linux/Interop.Libraries.cs b/src/libraries/Common/src/Interop/Linux/Interop.Libraries.cs index a8b0bd05a4079..e140e238c487d 100644 --- a/src/libraries/Common/src/Interop/Linux/Interop.Libraries.cs +++ b/src/libraries/Common/src/Interop/Linux/Interop.Libraries.cs @@ -8,7 +8,6 @@ internal static partial class Libraries // Duplicated from Android for Linux Bionic internal const string Liblog = "liblog"; - internal const string Odbc32 = "libodbc.so.2"; internal const string OpenLdap = "libldap-2.5.so.0"; internal const string MsQuic = "libmsquic.so"; } diff --git a/src/libraries/Common/src/Interop/OSX/Interop.Libraries.cs b/src/libraries/Common/src/Interop/OSX/Interop.Libraries.cs index 36cdea9e1bd9a..9ae92de254da1 100644 --- a/src/libraries/Common/src/Interop/OSX/Interop.Libraries.cs +++ b/src/libraries/Common/src/Interop/OSX/Interop.Libraries.cs @@ -10,7 +10,6 @@ internal static partial class Libraries internal const string CFNetworkLibrary = "/System/Library/Frameworks/CFNetwork.framework/CFNetwork"; internal const string libobjc = "/usr/lib/libobjc.dylib"; internal const string libproc = "/usr/lib/libproc.dylib"; - internal const string Odbc32 = "libodbc.2.dylib"; internal const string OpenLdap = "libldap.dylib"; internal const string SystemConfigurationLibrary = "/System/Library/Frameworks/SystemConfiguration.framework/SystemConfiguration"; internal const string AppleCryptoNative = "libSystem.Security.Cryptography.Native.Apple"; diff --git a/src/libraries/Common/src/Interop/Unix/Interop.Odbc.cs b/src/libraries/Common/src/Interop/Unix/Interop.Odbc.cs new file mode 100644 index 0000000000000..96e64bdda18a3 --- /dev/null +++ b/src/libraries/Common/src/Interop/Unix/Interop.Odbc.cs @@ -0,0 +1,38 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Reflection; +using System.Runtime.InteropServices; + +internal static partial class Interop +{ + internal static partial class Libraries + { + internal const string Odbc32 = "libodbc"; + } + + internal static partial class Odbc + { + internal static string GetNativeLibraryName() + { + if (OperatingSystem.IsMacOS() || OperatingSystem.IsIOS() || OperatingSystem.IsTvOS() || OperatingSystem.IsWatchOS()) + { + return "libodbc.2.dylib"; + } + return "libodbc.so.2"; + } + + static Odbc() + { + NativeLibrary.SetDllImportResolver(Assembly.GetExecutingAssembly(), (libraryName, assembly, searchPath) => + { + if (libraryName == Libraries.Odbc32) + { + return NativeLibrary.Load(GetNativeLibraryName(), assembly, default); + } + return default; + }); + } + } +} diff --git a/src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj b/src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj index b65bc3ae54d0c..30399b2f3b692 100644 --- a/src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj +++ b/src/libraries/System.Data.Odbc/src/System.Data.Odbc.csproj @@ -1,7 +1,7 @@ - $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-freebsd;$(NetCoreAppCurrent)-illumos;$(NetCoreAppCurrent)-solaris;$(NetCoreAppCurrent)-linux;$(NetCoreAppCurrent)-osx;$(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetCoreAppCurrent);$(NetCoreAppPrevious)-windows;$(NetCoreAppPrevious)-freebsd;$(NetCoreAppPrevious)-illumos;$(NetCoreAppPrevious)-solaris;$(NetCoreAppPrevious)-linux;$(NetCoreAppPrevious)-osx;$(NetCoreAppPrevious)-ios;$(NetCoreAppPrevious)-tvos;$(NetCoreAppPrevious);$(NetCoreAppMinimum)-windows;$(NetCoreAppMinimum)-freebsd;$(NetCoreAppMinimum)-linux;$(NetCoreAppMinimum)-osx;$(NetCoreAppMinimum);netstandard2.0;$(NetFrameworkMinimum) + $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetCoreAppCurrent);$(NetCoreAppPrevious)-windows;$(NetCoreAppPrevious)-unix;$(NetCoreAppPrevious);$(NetCoreAppMinimum)-windows;$(NetCoreAppMinimum)-unix;netstandard2.0;$(NetFrameworkMinimum) true $(NoWarn);CA2249;CA1838 false @@ -136,14 +136,9 @@ System.Data.Odbc.OdbcTransaction Link="Common\System\Runtime\InteropServices\HandleRefMarshaller.cs" /> - - - - - - + + diff --git a/src/libraries/System.Data.Odbc/tests/Helpers.cs b/src/libraries/System.Data.Odbc/tests/Helpers.cs index ccfbf0692d386..5db421ec5ced9 100644 --- a/src/libraries/System.Data.Odbc/tests/Helpers.cs +++ b/src/libraries/System.Data.Odbc/tests/Helpers.cs @@ -16,7 +16,7 @@ private static bool CheckOdbcIsAvailable() => #if TargetsWindows !PlatformDetection.IsWindowsNanoServer && (!PlatformDetection.IsWindowsServerCore || Environment.Is64BitProcess); #else - NativeLibrary.TryLoad(Interop.Libraries.Odbc32, out _); + NativeLibrary.TryLoad(Interop.Odbc.GetNativeLibraryName(), out _); #endif } } diff --git a/src/libraries/System.Data.Odbc/tests/System.Data.Odbc.Tests.csproj b/src/libraries/System.Data.Odbc/tests/System.Data.Odbc.Tests.csproj index c208fe67433a9..81645a849ccbb 100644 --- a/src/libraries/System.Data.Odbc/tests/System.Data.Odbc.Tests.csproj +++ b/src/libraries/System.Data.Odbc/tests/System.Data.Odbc.Tests.csproj @@ -1,6 +1,6 @@ - $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-freebsd;$(NetCoreAppCurrent)-linux;$(NetCoreAppCurrent)-osx;$(NetCoreAppCurrent)-ios;$(NetCoreAppCurrent)-tvos;$(NetFrameworkMinimum) + $(NetCoreAppCurrent)-windows;$(NetCoreAppCurrent)-unix;$(NetFrameworkMinimum) @@ -19,21 +19,9 @@ - - - - - - - - - - - + +