From f8584b1ccc3e559df7e06bc3963163a2d83a4451 Mon Sep 17 00:00:00 2001 From: Edward Neal <55035479+edwardneal@users.noreply.github.com> Date: Tue, 21 Jul 2026 15:24:37 +0100 Subject: [PATCH 1/8] Remove OS-specific builds from direct SNI references --- .../src/Interop/Windows/Sni/ISniNativeMethods.cs | 6 +----- .../src/Interop/Windows/Sni/SniNativeMethods.netcore.cs | 4 ++-- .../Interop/Windows/Sni/SniNativeMethodsArm64.netfx.cs | 4 ++-- .../Windows/Sni/SniNativeMethodsNotSupported.netfx.cs | 2 +- .../src/Interop/Windows/Sni/SniNativeMethodsX64.netfx.cs | 4 ++-- .../src/Interop/Windows/Sni/SniNativeMethodsX86.netfx.cs | 4 ++-- .../src/Interop/Windows/Sni/SniNativeWrapper.cs | 4 ---- .../src/Microsoft/Data/Sql/SqlDataSourceEnumerator.cs | 6 ------ ....windows.cs => SqlDataSourceEnumeratorNativeHelper.cs} | 4 ---- .../SqlClient/ConnectionPool/DbConnectionPoolIdentity.cs | 8 -------- ...rserSafeHandles.windows.cs => TdsParserSafeHandles.cs} | 4 ---- 11 files changed, 10 insertions(+), 40 deletions(-) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/Sql/{SqlDataSourceEnumeratorNativeHelper.windows.cs => SqlDataSourceEnumeratorNativeHelper.cs} (99%) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/{TdsParserSafeHandles.windows.cs => TdsParserSafeHandles.cs} (99%) diff --git a/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/ISniNativeMethods.cs b/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/ISniNativeMethods.cs index 194e61a4b6..7c4ee2486a 100644 --- a/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/ISniNativeMethods.cs +++ b/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/ISniNativeMethods.cs @@ -1,9 +1,7 @@ -// Licensed to the .NET Foundation under one or more agreements. +// 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. -#if _WINDOWS - using System; using System.Runtime.InteropServices; using System.Text; @@ -101,5 +99,3 @@ unsafe uint SniSecGenClientContextWrapper( uint SniWriteSyncOverAsync(SNIHandle pConn, SNIPacket pPacket); } } - -#endif diff --git a/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethods.netcore.cs b/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethods.netcore.cs index 32109770e0..dc78405f41 100644 --- a/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethods.netcore.cs +++ b/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethods.netcore.cs @@ -1,8 +1,8 @@ -// Licensed to the .NET Foundation under one or more agreements. +// 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. -#if NET && _WINDOWS +#if NET using System; using System.Runtime.InteropServices; diff --git a/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethodsArm64.netfx.cs b/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethodsArm64.netfx.cs index c39c1dbefa..a450e706ad 100644 --- a/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethodsArm64.netfx.cs +++ b/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethodsArm64.netfx.cs @@ -1,8 +1,8 @@ -// Licensed to the .NET Foundation under one or more agreements. +// 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. -#if NETFRAMEWORK && _WINDOWS +#if NETFRAMEWORK using System; using System.Runtime.InteropServices; diff --git a/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethodsNotSupported.netfx.cs b/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethodsNotSupported.netfx.cs index 0d8600f193..7139ee0b08 100644 --- a/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethodsNotSupported.netfx.cs +++ b/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethodsNotSupported.netfx.cs @@ -2,7 +2,7 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#if NETFRAMEWORK && _WINDOWS +#if NETFRAMEWORK using System; using System.Runtime.InteropServices; diff --git a/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethodsX64.netfx.cs b/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethodsX64.netfx.cs index 0849e1a22d..293e0432c5 100644 --- a/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethodsX64.netfx.cs +++ b/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethodsX64.netfx.cs @@ -1,8 +1,8 @@ -// Licensed to the .NET Foundation under one or more agreements. +// 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. -#if NETFRAMEWORK && _WINDOWS +#if NETFRAMEWORK using System; using System.Runtime.InteropServices; diff --git a/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethodsX86.netfx.cs b/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethodsX86.netfx.cs index 270a522aa6..187acb3fe7 100644 --- a/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethodsX86.netfx.cs +++ b/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeMethodsX86.netfx.cs @@ -1,8 +1,8 @@ -// Licensed to the .NET Foundation under one or more agreements. +// 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. -#if NETFRAMEWORK && _WINDOWS +#if NETFRAMEWORK using System; using System.Runtime.InteropServices; diff --git a/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeWrapper.cs b/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeWrapper.cs index 62961901ff..5d4ba1e83a 100644 --- a/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeWrapper.cs +++ b/src/Microsoft.Data.SqlClient/src/Interop/Windows/Sni/SniNativeWrapper.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. - #if _WINDOWS - using System; using System.Buffers; using System.Diagnostics; @@ -452,5 +450,3 @@ private static void MarshalConsumerInfo(ConsumerInfo consumerInfo, ref SniConsum #endregion } } - -#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Sql/SqlDataSourceEnumerator.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Sql/SqlDataSourceEnumerator.cs index 0356d7bcd3..7777e558b9 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Sql/SqlDataSourceEnumerator.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Sql/SqlDataSourceEnumerator.cs @@ -27,16 +27,10 @@ public override DataTable GetDataSources() #if NETFRAMEWORK return SqlDataSourceEnumeratorNativeHelper.GetDataSources(); #else - - #if _UNIX - return SqlDataSourceEnumeratorManagedHelper.GetDataSources(); - #else return SqlClient.LocalAppContextSwitches.UseManagedNetworking ? SqlDataSourceEnumeratorManagedHelper.GetDataSources() : SqlDataSourceEnumeratorNativeHelper.GetDataSources(); #endif - - #endif } } } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Sql/SqlDataSourceEnumeratorNativeHelper.windows.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Sql/SqlDataSourceEnumeratorNativeHelper.cs similarity index 99% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/Sql/SqlDataSourceEnumeratorNativeHelper.windows.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/Sql/SqlDataSourceEnumeratorNativeHelper.cs index a6325d9990..d7a2a0f832 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Sql/SqlDataSourceEnumeratorNativeHelper.windows.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Sql/SqlDataSourceEnumeratorNativeHelper.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#if _WINDOWS - using System; using System.Data; using System.Diagnostics; @@ -175,5 +173,3 @@ private static DataTable ParseServerEnumString(string serverInstances) } } } - -#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolIdentity.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolIdentity.cs index 320e59fb48..2056395688 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolIdentity.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolIdentity.cs @@ -57,16 +57,10 @@ internal static DbConnectionPoolIdentity GetCurrent() #if NETFRAMEWORK return GetCurrentNative(); #else - - #if _UNIX - return GetCurrentManaged(); - #else return LocalAppContextSwitches.UseManagedNetworking ? GetCurrentManaged() : GetCurrentNative(); #endif - - #endif } #if NETFRAMEWORK @@ -94,7 +88,6 @@ private static DbConnectionPoolIdentity GetCurrentManaged() return current; } - #if _WINDOWS private static DbConnectionPoolIdentity GetCurrentNative() { DbConnectionPoolIdentity current; @@ -124,7 +117,6 @@ private static DbConnectionPoolIdentity GetCurrentNative() s_lastIdentity = current; return current; } - #endif } } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserSafeHandles.windows.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserSafeHandles.cs similarity index 99% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserSafeHandles.windows.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserSafeHandles.cs index 8242dd997f..2f591294d4 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserSafeHandles.windows.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserSafeHandles.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#if _WINDOWS - using System; using System.Diagnostics; using System.Runtime.InteropServices; @@ -280,5 +278,3 @@ protected override bool ReleaseHandle() } } } - -#endif From 3746c13b18a68b69351e314bf298dd205ec0f936 Mon Sep 17 00:00:00 2001 From: Edward Neal <55035479+edwardneal@users.noreply.github.com> Date: Tue, 21 Jul 2026 15:36:07 +0100 Subject: [PATCH 2/8] Merge LocalDB handling --- .../{LocalDbApi.windows.cs => LocalDbApi.cs} | 17 ++++++++++----- .../Data/SqlClient/LocalDb/LocalDbApi.unix.cs | 21 ------------------- 2 files changed, 12 insertions(+), 26 deletions(-) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalDb/{LocalDbApi.windows.cs => LocalDbApi.cs} (97%) delete mode 100644 src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalDb/LocalDbApi.unix.cs diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalDb/LocalDbApi.windows.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalDb/LocalDbApi.cs similarity index 97% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalDb/LocalDbApi.windows.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalDb/LocalDbApi.cs index c0674ca6db..da1e613c44 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalDb/LocalDbApi.windows.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalDb/LocalDbApi.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#if _WINDOWS - using System; using System.Diagnostics; using System.Globalization; @@ -276,7 +274,12 @@ internal static void DemandLocalDbPermissions() // localDB can also have a format of np:\\.\pipe\LOCALDB#\tsql\query internal static string GetLocalDbInstanceNameFromServerName(string serverName) { - if (serverName is not null) + // LocalDB is only supported on Windows + if (!OsConstants.IsWindows) + { + return null; + } + else if (serverName is not null) { // it can start with spaces if specified in quotes // Memory allocation is reduced by using ReadOnlySpan @@ -300,6 +303,12 @@ internal static string GetLocalDbInstanceNameFromServerName(string serverName) internal static string GetLocalDbMessage(int hrCode) { + if (!OsConstants.IsWindows) + { + // LocalDB is not available for Unix and hence it cannot be supported. + throw new PlatformNotSupportedException(Strings.LocalDBNotSupported); + } + Debug.Assert(hrCode < 0, "HRCode does not indicate error"); try { @@ -422,5 +431,3 @@ internal InstanceInfo(string version) #endif } } - -#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalDb/LocalDbApi.unix.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalDb/LocalDbApi.unix.cs deleted file mode 100644 index b016c7dc97..0000000000 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalDb/LocalDbApi.unix.cs +++ /dev/null @@ -1,21 +0,0 @@ -// 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. - -#if _UNIX - -using System; - -namespace Microsoft.Data.SqlClient.LocalDb -{ - internal static class LocalDbApi - { - internal static string GetLocalDbInstanceNameFromServerName(string serverName) => - null; - - internal static string GetLocalDbMessage(int hrCode) => - throw new PlatformNotSupportedException(Strings.LocalDBNotSupported); // LocalDB is not available for Unix and hence it cannot be supported. - } -} - -#endif From f047b85b112bb8bf21ff61e418ccf41dab213ef1 Mon Sep 17 00:00:00 2001 From: Edward Neal <55035479+edwardneal@users.noreply.github.com> Date: Tue, 21 Jul 2026 15:44:56 +0100 Subject: [PATCH 3/8] Merge PacketHandle handling --- ...ore.windows.cs => PacketHandle.netcore.cs} | 3 +- .../SqlClient/PacketHandle.netcore.unix.cs | 57 ------------------- 2 files changed, 1 insertion(+), 59 deletions(-) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/{PacketHandle.netcore.windows.cs => PacketHandle.netcore.cs} (96%) delete mode 100644 src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.unix.cs diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.windows.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.cs similarity index 96% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.windows.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.cs index 4e675fc5b0..4bce65d8f3 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.windows.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.cs @@ -3,7 +3,7 @@ // See the LICENSE file in the project root for more information. // @TODO: Introduce polymorphism to remove need for this level of indirection -#if NET && _WINDOWS +#if NET using System; @@ -18,7 +18,6 @@ namespace Microsoft.Data.SqlClient /// /// /// It is a ref struct so that it can only be used to transport the handles and not store them. - /// If you change this type you must also change the version for the other platform. /// internal readonly ref struct PacketHandle { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.unix.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.unix.cs deleted file mode 100644 index 4060edfb38..0000000000 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PacketHandle.netcore.unix.cs +++ /dev/null @@ -1,57 +0,0 @@ -// 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. - -// @TODO: Introduce polymorphism to remove need for this level of indirection -// @TODO: Also, why do we have any other type besides managed defined here? -#if NET && _UNIX - -namespace Microsoft.Data.SqlClient -{ - /// - /// This structure is used for transporting packet handle references between the - /// TdsParserStateObject base class and Managed or Native implementations. It prevents the - /// native IntPtr type from being boxed and prevents the need to cast from object which loses - /// compile time type safety. It carries type information so that assertions about the type of - /// handle can be made in the implemented abstract methods. - /// - /// - /// It is a ref struct so that it can only be used to transport the handles and not store them. - /// If you change this type you must also change the version for the other platform. - /// - internal readonly ref struct PacketHandle - { - /// - /// PacketHandle is transporting a native pointer. The NativePointer field is valid. - /// A PacketHandle has this type when managed code is referencing a pointer to a - /// packet which has been read from the native SNI layer. - /// - public const int NativePointerType = 1; - /// - /// PacketHandle is transporting a native packet. The NativePacket field is valid. - /// A PacketHandle has this type when managed code is directly referencing a packet - /// which is due to be passed to the native SNI layer. - /// - public const int NativePacketType = 2; - /// - /// PacketHandle is transporting a managed packet. The ManagedPacket field is valid. - /// A PacketHandle used by the managed SNI layer will always have this type. - /// - public const int ManagedPacketType = 3; - - // @TODO: To auto-properties - public readonly ManagedSni.SniPacket ManagedPacket; - public readonly int Type; - - private PacketHandle(ManagedSni.SniPacket managedPacket, int type) - { - Type = type; - ManagedPacket = managedPacket; - } - - public static PacketHandle FromManagedPacket(ManagedSni.SniPacket managedPacket) => - new PacketHandle(managedPacket, ManagedPacketType); - } -} - -#endif From 0d5f6941e2ac50ddf1fdaaa566a3b802e01a062d Mon Sep 17 00:00:00 2001 From: Edward Neal <55035479+edwardneal@users.noreply.github.com> Date: Tue, 21 Jul 2026 15:48:24 +0100 Subject: [PATCH 4/8] Merge SessionHandle handling --- ...re.windows.cs => SessionHandle.netcore.cs} | 3 +- .../SqlClient/SessionHandle.netcore.unix.cs | 43 ------------------- 2 files changed, 1 insertion(+), 45 deletions(-) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/{SessionHandle.netcore.windows.cs => SessionHandle.netcore.cs} (94%) delete mode 100644 src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.unix.cs diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.windows.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.cs similarity index 94% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.windows.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.cs index dcac01c534..019bed388b 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.windows.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.cs @@ -3,7 +3,7 @@ // See the LICENSE file in the project root for more information. // @TODO: Merge with other implementations (and/or introduce polymorphism to handle this indirection) -#if NET && _WINDOWS +#if NET namespace Microsoft.Data.SqlClient { @@ -15,7 +15,6 @@ namespace Microsoft.Data.SqlClient /// /// /// It is a ref struct so that it can only be used to transport the handles and not store them. - /// If you change this type you must also change the version for the other platform. /// internal readonly ref struct SessionHandle { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.unix.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.unix.cs deleted file mode 100644 index 8f82506bc5..0000000000 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SessionHandle.netcore.unix.cs +++ /dev/null @@ -1,43 +0,0 @@ -// 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. - -// @TODO: Merge with SessionHandle.windows (and/or introduce polymorphism to handle this indirection) -// @TODO: Also, why do we have native handle type defined in Unix which doesn't ever have a native handle type? -#if NET && _UNIX - -namespace Microsoft.Data.SqlClient -{ - /// - /// This structure is used for transporting packet handle references between the - /// TdsParserStateObject base class and Managed or Native implementations. It carries type - /// information so that assertions about the type of handle can be made in the implemented - /// abstract methods. - /// - /// - /// It is a ref struct so that it can only be used to transport the handles and not store them. - /// If you change this type you must also change the version for the other platform. - /// - internal readonly ref struct SessionHandle - { - public const int NativeHandleType = 1; - public const int ManagedHandleType = 2; - - // @TODO: Auto-properties - public readonly ManagedSni.SniHandle ManagedHandle; - public readonly int Type; - - public SessionHandle(ManagedSni.SniHandle managedHandle, int type) - { - Type = type; - ManagedHandle = managedHandle; - } - - public bool IsNull => ManagedHandle is null; - - public static SessionHandle FromManagedSession(ManagedSni.SniHandle managedSessionHandle) => - new SessionHandle(managedSessionHandle, ManagedHandleType); - } -} - -#endif From 4a86f1e6c0d8faa88e1ff82c38bb22af7819e1bc Mon Sep 17 00:00:00 2001 From: Edward Neal <55035479+edwardneal@users.noreply.github.com> Date: Tue, 21 Jul 2026 15:50:48 +0100 Subject: [PATCH 5/8] Merge TdsParserStateObjectNative and NativeSspiContextProvider --- ...textProvider.windows.cs => NativeSspiContextProvider.cs} | 6 +----- ...bjectNative.windows.cs => TdsParserStateObjectNative.cs} | 4 ---- 2 files changed, 1 insertion(+), 9 deletions(-) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/{NativeSspiContextProvider.windows.cs => NativeSspiContextProvider.cs} (96%) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/{TdsParserStateObjectNative.windows.cs => TdsParserStateObjectNative.cs} (99%) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/NativeSspiContextProvider.windows.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/NativeSspiContextProvider.cs similarity index 96% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/NativeSspiContextProvider.windows.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/NativeSspiContextProvider.cs index b6d65d4452..94e7652874 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/NativeSspiContextProvider.windows.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/NativeSspiContextProvider.cs @@ -1,9 +1,7 @@ -// Licensed to the .NET Foundation under one or more agreements. +// 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. -#if _WINDOWS - using System; using System.Buffers; using System.Diagnostics; @@ -85,5 +83,3 @@ protected override bool GenerateContext(ReadOnlySpan incomingBlob, IBuffer } } } - -#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectNative.windows.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectNative.cs similarity index 99% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectNative.windows.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectNative.cs index 7812860b5e..a57a46658f 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectNative.windows.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectNative.cs @@ -2,8 +2,6 @@ // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. -#if _WINDOWS - using System; using System.Collections.Generic; using System.Diagnostics; @@ -532,5 +530,3 @@ public void Dispose() } } } - -#endif From 75a2d4a23854d4a3fda7ed4f67fd00d1189f9e36 Mon Sep 17 00:00:00 2001 From: Edward Neal <55035479+edwardneal@users.noreply.github.com> Date: Tue, 21 Jul 2026 15:55:30 +0100 Subject: [PATCH 6/8] Merge TdsParserStateObjectFactory --- ...dows.cs => TdsParserStateObjectFactory.cs} | 6 +--- .../TdsParserStateObjectFactory.unix.cs | 36 ------------------- 2 files changed, 1 insertion(+), 41 deletions(-) rename src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/{TdsParserStateObjectFactory.windows.cs => TdsParserStateObjectFactory.cs} (96%) delete mode 100644 src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.unix.cs diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.windows.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.cs similarity index 96% rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.windows.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.cs index a54873cb21..abe66c38a5 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.windows.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.cs @@ -1,9 +1,7 @@ -// Licensed to the .NET Foundation under one or more agreements. +// 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. -#if _WINDOWS - #if NET using Microsoft.Data.SqlClient.ManagedSni; using Microsoft.Data.SqlClient.Internal; @@ -72,5 +70,3 @@ internal TdsParserStateObject CreateSessionObject(TdsParser tdsParser, TdsParser } } } - -#endif diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.unix.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.unix.cs deleted file mode 100644 index 61817eb0ed..0000000000 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObjectFactory.unix.cs +++ /dev/null @@ -1,36 +0,0 @@ -// 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. - -#if NET && _UNIX - -using Microsoft.Data.SqlClient.ManagedSni; - -namespace Microsoft.Data.SqlClient -{ - internal sealed class TdsParserStateObjectFactory - { - public static readonly TdsParserStateObjectFactory Singleton = new TdsParserStateObjectFactory(); - - public EncryptionOptions EncryptionOptions => ManagedSni.SniLoadHandle.Options; - - public uint SNIStatus => ManagedSni.SniLoadHandle.Status; - - /// - /// Verify client encryption possibility. - /// - public bool ClientOSEncryptionSupport => ManagedSni.SniLoadHandle.ClientOSEncryptionSupport; - - public TdsParserStateObject CreateTdsParserStateObject(TdsParser parser) - { - return new TdsParserStateObjectManaged(parser); - } - - internal TdsParserStateObject CreateSessionObject(TdsParser tdsParser, TdsParserStateObject _pMarsPhysicalConObj, bool v) - { - return new TdsParserStateObjectManaged(tdsParser, _pMarsPhysicalConObj, true); - } - } -} - -#endif From 5e8eae181969e603172cc07a1ff8ca8d665433c6 Mon Sep 17 00:00:00 2001 From: Edward Neal <55035479+edwardneal@users.noreply.github.com> Date: Tue, 21 Jul 2026 16:03:37 +0100 Subject: [PATCH 7/8] Cleanup of csproj --- .../src/Microsoft.Data.SqlClient.csproj | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csproj index dc327b024a..7194f0e8db 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/src/Microsoft.Data.SqlClient.csproj @@ -19,11 +19,6 @@ $(TargetOs.ToLower()) - - - - $(DefineConstants);_UNIX - $(DefineConstants);_WINDOWS @@ -231,11 +226,11 @@ - + + Condition="'$(TargetFramework)' != 'net462'"> ILLink.Substitutions.xml From 99703db869cc7113f96c7e6cc18084de71eb9711 Mon Sep 17 00:00:00 2001 From: Edward Neal <55035479+edwardneal@users.noreply.github.com> Date: Tue, 21 Jul 2026 22:25:17 +0100 Subject: [PATCH 8/8] Code review: remove unnecessary conditional compilation --- .../Data/SqlClient/ConnectionPool/DbConnectionPoolIdentity.cs | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolIdentity.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolIdentity.cs index 2056395688..940a10271f 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolIdentity.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ConnectionPool/DbConnectionPoolIdentity.cs @@ -54,13 +54,9 @@ public override int GetHashCode() internal static DbConnectionPoolIdentity GetCurrent() { - #if NETFRAMEWORK - return GetCurrentNative(); - #else return LocalAppContextSwitches.UseManagedNetworking ? GetCurrentManaged() : GetCurrentNative(); - #endif } #if NETFRAMEWORK