From a9ee053e83e69bbc7504cc5c1fdb3bd9dee55c90 Mon Sep 17 00:00:00 2001 From: Erik Ejlskov Jensen Date: Tue, 7 May 2024 10:51:46 +0200 Subject: [PATCH 1/3] streamline conditional compilation symbols fixes #2484 --- .../netcore/ref/Microsoft.Data.SqlClient.cs | 6 +++--- .../src/System/Net/Logging/NetEventSource.Common.cs | 4 ++-- .../Data/ProviderBase/DbConnectionPool.NetCoreApp.cs | 2 +- .../Microsoft/Data/ProviderBase/DbConnectionPool.cs | 2 +- .../src/Microsoft/Data/SqlClient/SNI/SNITcpHandle.cs | 2 +- .../src/Microsoft/Data/SqlClient/SqlCommand.cs | 4 ++-- .../Data/SqlClient/SqlDelegatedTransaction.cs | 8 ++++---- .../Data/SqlClient/SqlInternalConnectionTds.cs | 2 +- .../src/Microsoft/Data/SqlClient/TdsParser.cs | 2 +- .../Data/SqlClient/TdsParserStateObjectNative.cs | 2 +- .../Microsoft/Data/SqlTypes/SqlFileStream.Windows.cs | 4 ++-- .../src/Microsoft/Data/Common/AdapterUtil.Windows.cs | 4 ++-- .../src/Microsoft/Data/Common/AdapterUtil.cs | 2 +- .../DbConnectionPoolAuthenticationContext.cs | 2 +- .../Data/Sql/SqlDataSourceEnumeratorNativeHelper.cs | 6 +++--- .../ActiveDirectoryAuthenticationProvider.cs | 6 ++---- .../Data/SqlClient/LocalAppContextSwitches.cs | 2 +- .../Reliability/SqlConfigurableRetryLogicLoader.cs | 2 +- .../SqlClient/SSPI/ManagedSSPIContextProvider.cs | 2 +- .../Microsoft/Data/SqlClient/Server/ValueUtilsSmi.cs | 4 ++-- .../src/Microsoft/Data/SqlClient/SqlBuffer.cs | 2 +- .../Microsoft/Data/SqlClient/SqlCommandBuilder.cs | 2 -- .../Microsoft/Data/SqlClient/SqlConnectionString.cs | 2 +- .../Data/SqlClient/SqlConnectionStringBuilder.cs | 2 +- .../src/Microsoft/Data/SqlClient/SqlDependency.cs | 4 ++-- .../SqlDependencyUtils.AssemblyLoadContext.cs | 2 +- .../Microsoft/Data/SqlClient/SqlDependencyUtils.cs | 2 +- .../src/Microsoft/Data/SqlClient/SqlParameter.cs | 2 +- .../Data/SqlClient/TdsParserSafeHandles.Windows.cs | 2 +- .../Microsoft/Data/SqlClient/TdsParserStateObject.cs | 2 +- .../src/Microsoft/Data/SqlClient/TdsValueSetter.cs | 12 ++++++------ .../src/Resources/StringsHelper.cs | 2 +- .../src/System/Diagnostics/CodeAnalysis.cs | 2 +- .../tests/FunctionalTests/SqlErrorTest.cs | 2 +- .../tests/FunctionalTests/SqlExceptionTest.cs | 2 +- .../tests/ManualTests/DataCommon/DataTestUtility.cs | 4 ++-- .../SQL/InstanceNameTest/InstanceNameTest.cs | 2 +- .../SQL/RetryLogic/RetryLogicConfigHelper.cs | 2 +- 38 files changed, 57 insertions(+), 61 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs index a0acf34a33..b228b0a137 100644 --- a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs +++ b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs @@ -478,7 +478,7 @@ public static partial class SqlClientMetaDataCollectionNames /// public static readonly string StructuredTypeMembers; } -#if NETCOREAPP +#if NET6_0_OR_GREATER /// public enum SqlConnectionAttestationProtocol { @@ -1017,7 +1017,7 @@ public SqlConnectionStringBuilder(string connectionString) { } [System.ComponentModel.DisplayNameAttribute("Data Source")] [System.ComponentModel.RefreshPropertiesAttribute(System.ComponentModel.RefreshProperties.All)] public string DataSource { get { throw null; } set { } } -#if NETCOREAPP +#if NET6_0_OR_GREATER /// [System.ComponentModel.DisplayNameAttribute("Attestation Protocol")] [System.ComponentModel.RefreshPropertiesAttribute(System.ComponentModel.RefreshProperties.All)] @@ -1444,7 +1444,7 @@ internal SqlException() { } public byte State { get { throw null; } } /// -#if !NET6_0_OR_GREATER +#if NETFRAMEWORK [System.Security.Permissions.SecurityPermissionAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Flags = System.Security.Permissions.SecurityPermissionFlag.SerializationFormatter)] #endif #if NET8_0_OR_GREATER diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Logging/NetEventSource.Common.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Logging/NetEventSource.Common.cs index 5b908a3b8e..1e56818132 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Logging/NetEventSource.Common.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/System/Net/Logging/NetEventSource.Common.cs @@ -13,7 +13,7 @@ using System.Diagnostics.Tracing; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; -#if net462 +#if NETFRAMEWORK using System.Security; #endif @@ -45,7 +45,7 @@ namespace System.Net // method that takes an object and optionally provides a string representation of it, in case a particular library wants to customize further. /// Provides logging facilities for System.Net libraries. -#if net462 +#if NETFRAMEWORK [SecuritySafeCritical] #endif internal sealed partial class NetEventSource : EventSource diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPool.NetCoreApp.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPool.NetCoreApp.cs index 9f330c3dcc..4a59e0b858 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPool.NetCoreApp.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPool.NetCoreApp.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 NETCOREAPP +#if NET6_0_OR_GREATER using System.Diagnostics; using Microsoft.Data.Common; diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs index 7858adc93c..3bf8a9d561 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/ProviderBase/DbConnectionPool.cs @@ -776,7 +776,7 @@ private DbConnectionInternal CreateObject(DbConnection owningObject, DbConnectio throw; } -#if NETCOREAPP +#if NET6_0_OR_GREATER if (!IsBlockingPeriodEnabled()) { throw; diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNITcpHandle.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNITcpHandle.cs index d12e91ad62..9d415bcfc8 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNITcpHandle.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNITcpHandle.cs @@ -1008,7 +1008,7 @@ public override void KillConnection() internal static void SetKeepAliveValues(ref Socket socket) { -#if NETCOREAPP +#if NET6_0_OR_GREATER socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true); socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveInterval, 1); socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveTime, 30); diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs index d01c686d04..94325d3c88 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs @@ -3994,7 +3994,7 @@ private SqlDataReader GetParameterEncryptionDataReader(out Task returnTask, Task SqlCommand command = (SqlCommand)state; bool processFinallyBlockAsync = true; bool decrementAsyncCountInFinallyBlockAsync = true; -#if !NET6_0_OR_GREATER +#if NETFRAMEWORK RuntimeHelpers.PrepareConstrainedRegions(); #endif try @@ -4068,7 +4068,7 @@ private SqlDataReader GetParameterEncryptionDataReaderAsync(out Task returnTask, bool processFinallyBlockAsync = true; bool decrementAsyncCountInFinallyBlockAsync = true; -#if !NET6_0_OR_GREATER +#if NETFRAMEWORK RuntimeHelpers.PrepareConstrainedRegions(); #endif try diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlDelegatedTransaction.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlDelegatedTransaction.cs index 3ed756eef0..2f9e1e8e06 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlDelegatedTransaction.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlDelegatedTransaction.cs @@ -81,7 +81,7 @@ public void Initialize() SqlInternalConnection connection = _connection; SqlConnection usersConnection = connection.Connection; SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.Initialize | RES | CPOOL | Object Id {0}, Client Connection Id {1}, delegating transaction.", ObjectID, usersConnection?.ClientConnectionId); -#if !NET6_0_OR_GREATER +#if NETFRAMEWORK RuntimeHelpers.PrepareConstrainedRegions(); #endif try @@ -146,7 +146,7 @@ public byte[] Promote() { SqlConnection usersConnection = connection.Connection; SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.Promote | RES | CPOOL | Object Id {0}, Client Connection Id {1}, promoting transaction.", ObjectID, usersConnection?.ClientConnectionId); -#if !NET6_0_OR_GREATER +#if NETFRAMEWORK RuntimeHelpers.PrepareConstrainedRegions(); #endif try @@ -256,7 +256,7 @@ public void Rollback(SinglePhaseEnlistment enlistment) { SqlConnection usersConnection = connection.Connection; SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.Rollback | RES | CPOOL | Object Id {0}, Client Connection Id {1}, rolling back transaction.", ObjectID, usersConnection?.ClientConnectionId); -#if !NET6_0_OR_GREATER +#if NETFRAMEWORK RuntimeHelpers.PrepareConstrainedRegions(); #endif try @@ -343,7 +343,7 @@ public void SinglePhaseCommit(SinglePhaseEnlistment enlistment) { SqlConnection usersConnection = connection.Connection; SqlClientEventSource.Log.TryTraceEvent("SqlDelegatedTransaction.SinglePhaseCommit | RES | CPOOL | Object Id {0}, Client Connection Id {1}, committing transaction.", ObjectID, usersConnection?.ClientConnectionId); -#if !NET6_0_OR_GREATER +#if NETFRAMEWORK RuntimeHelpers.PrepareConstrainedRegions(); #endif try diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs index dd7043d629..5ef3d781ea 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlInternalConnectionTds.cs @@ -2300,7 +2300,7 @@ internal bool TryGetFedAuthTokenLocked(SqlFedAuthInfo fedAuthInfo, DbConnectionP bool authenticationContextLocked = false; // Prepare CER to ensure the lock on authentication context is released. -#if !NET6_0_OR_GREATER +#if NETFRAMEWORK RuntimeHelpers.PrepareConstrainedRegions(); #endif try diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs index 0d3c0a01b5..a2e510dd01 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs @@ -1776,7 +1776,7 @@ internal void WriteInt(int v, TdsParserStateObject stateObj) internal static void WriteInt(Span buffer, int value) { -#if NETCOREAPP +#if NET6_0_OR_GREATER BinaryPrimitives.TryWriteInt32LittleEndian(buffer, value); #else buffer[0] = (byte)(value & 0xff); diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectNative.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectNative.cs index 6f26250072..611a003177 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectNative.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectNative.cs @@ -409,7 +409,7 @@ internal override uint WaitForSSLHandShakeToComplete(out int protocolVersion) { protocolVersion = (int)SslProtocols.Tls12; } -#if NETCOREAPP +#if NET6_0_OR_GREATER else if (nativeProtocol.HasFlag(NativeProtocols.SP_PROT_TLS1_3_CLIENT) || nativeProtocol.HasFlag(NativeProtocols.SP_PROT_TLS1_3_SERVER)) { /* The SslProtocols.Tls13 is supported by netcoreapp3.1 and later */ diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlTypes/SqlFileStream.Windows.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlTypes/SqlFileStream.Windows.cs index 78682e917f..319e0d0169 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlTypes/SqlFileStream.Windows.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlTypes/SqlFileStream.Windows.cs @@ -297,7 +297,7 @@ public override void Flush() } /// -#if !NET6_0_OR_GREATER +#if NETFRAMEWORK [HostProtection(ExternalThreading = true)] #endif public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state) @@ -318,7 +318,7 @@ public override int EndRead(IAsyncResult asyncResult) } /// -#if !NET6_0_OR_GREATER +#if NETFRAMEWORK [HostProtection(ExternalThreading = true)] #endif public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback, object state) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.Windows.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.Windows.cs index abeadf86b7..6fbdfcb343 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.Windows.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.Windows.cs @@ -26,7 +26,7 @@ internal static partial class ADP [ResourceConsumption(ResourceScope.Machine)] internal static object LocalMachineRegistryValue(string subkey, string queryvalue) { // MDAC 77697 -#if !NET6_0_OR_GREATER +#if NETFRAMEWORK (new RegistryPermission(RegistryPermissionAccess.Read, "HKEY_LOCAL_MACHINE\\" + subkey)).Assert(); // MDAC 62028 #endif try @@ -43,7 +43,7 @@ internal static object LocalMachineRegistryValue(string subkey, string queryvalu ADP.TraceExceptionWithoutRethrow(e); return null; } -#if !NET6_0_OR_GREATER +#if NETFRAMEWORK finally { RegistryPermission.RevertAssert(); diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.cs index 1ded2eef3a..dcbb89a248 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Common/AdapterUtil.cs @@ -668,7 +668,7 @@ private static long TimerToSeconds(long timerValue) /// Note: In Longhorn you'll be able to rename a machine without /// rebooting. Therefore, don't cache this machine name. /// -#if !NET6_0_OR_GREATER +#if NETFRAMEWORK [EnvironmentPermission(SecurityAction.Assert, Read = "COMPUTERNAME")] #endif internal static string MachineName() => Environment.MachineName; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolAuthenticationContext.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolAuthenticationContext.cs index 213f4b8b25..29ac7fee31 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolAuthenticationContext.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/ProviderBase/DbConnectionPoolAuthenticationContext.cs @@ -102,7 +102,7 @@ internal bool LockToUpdate() /// /// Release the lock which was obtained through LockToUpdate. /// -#if !NET6_0_OR_GREATER +#if NETFRAMEWORK [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] #endif internal void ReleaseLockToUpdate() diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Sql/SqlDataSourceEnumeratorNativeHelper.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Sql/SqlDataSourceEnumeratorNativeHelper.cs index 9118e341af..a236d5645e 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Sql/SqlDataSourceEnumeratorNativeHelper.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/Sql/SqlDataSourceEnumeratorNativeHelper.cs @@ -25,7 +25,7 @@ internal static class SqlDataSourceEnumeratorNativeHelper /// internal static DataTable GetDataSources() { -#if !NET6_0_OR_GREATER +#if NETFRAMEWORK (new NamedPermissionSet("FullTrust")).Demand(); // SQLBUDT 244304 #endif char[] buffer = null; @@ -37,13 +37,13 @@ internal static DataTable GetDataSources() bool more = true; bool failure = false; IntPtr handle = ADP.s_ptrZero; -#if !NET6_0_OR_GREATER +#if NETFRAMEWORK RuntimeHelpers.PrepareConstrainedRegions(); #endif try { long s_timeoutTime = TdsParserStaticMethods.GetTimeoutSeconds(ADP.DefaultCommandTimeout); -#if !NET6_0_OR_GREATER +#if NETFRAMEWORK RuntimeHelpers.PrepareConstrainedRegions(); #endif try diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ActiveDirectoryAuthenticationProvider.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ActiveDirectoryAuthenticationProvider.cs index 75b55847f7..d40f59c78b 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ActiveDirectoryAuthenticationProvider.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ActiveDirectoryAuthenticationProvider.cs @@ -207,7 +207,7 @@ public override async Task AcquireTokenAsync(SqlAuthenti */ string redirectUri = s_nativeClientRedirectUri; -#if NETCOREAPP +#if NET6_0_OR_GREATER if (parameters.AuthenticationMethod != SqlAuthenticationMethod.ActiveDirectoryDeviceCodeFlow) { redirectUri = "http://localhost"; @@ -361,7 +361,7 @@ private static async Task AcquireTokenInteractiveDeviceFlo if (authenticationMethod == SqlAuthenticationMethod.ActiveDirectoryInteractive) { CancellationTokenSource ctsInteractive = new CancellationTokenSource(); -#if NETCOREAPP +#if NET6_0_OR_GREATER /* * On .NET Core, MSAL will start the system browser as a separate process. MSAL does not have control over this browser, * but once the user finishes authentication, the web page is redirected in such a way that MSAL can intercept the Uri. @@ -492,8 +492,6 @@ private IPublicClientApplication CreateClientAppInstance(PublicClientAppKey publ .WithParentActivityOrWindow(_iWin32WindowFunc) .Build(); } -#endif -#if !NETCOREAPP else #endif { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs index ed2c4aedf7..5d35159d60 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs @@ -26,7 +26,7 @@ private enum Tristate : byte private static Tristate s_makeReadAsyncBlocking; private static Tristate s_useMinimumLoginTimeout; -#if !NETFRAMEWORK +#if NET6_0_OR_GREATER static LocalAppContextSwitches() { IAppContextSwitchOverridesSection appContextSwitch = AppConfigManager.FetchConfigurationSection(AppContextSwitchOverridesSection.Name); diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryLogicLoader.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryLogicLoader.cs index a4d197d5e2..ab69ed288f 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryLogicLoader.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryLogicLoader.cs @@ -43,7 +43,7 @@ public SqlConfigurableRetryLogicLoader(ISqlConfigurableRetryConnectionSection co string cnnSectionName = SqlConfigurableRetryConnectionSection.Name, string cmdSectionName = SqlConfigurableRetryCommandSection.Name) { -#if !NETFRAMEWORK +#if NET6_0_OR_GREATER // Just only one subscription to this event is required. // This class isn't supposed to be called more than one time; // SqlConfigurableRetryLogicManager manages a single instance of this class. diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/ManagedSSPIContextProvider.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/ManagedSSPIContextProvider.cs index 25fb2cadae..14bc318396 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/ManagedSSPIContextProvider.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/ManagedSSPIContextProvider.cs @@ -1,4 +1,4 @@ -#if !NETFRAMEWORK && !NET7_0_OR_GREATER +#if NET6_0 using Microsoft.Data.SqlClient.SNI; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/ValueUtilsSmi.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/ValueUtilsSmi.cs index 4662bc6012..da931ae53f 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/ValueUtilsSmi.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/ValueUtilsSmi.cs @@ -15,7 +15,7 @@ using Microsoft.Data.Common; using Microsoft.Data.SqlTypes; -#if !NETFRAMEWORK +#if NET6_0_OR_GREATER using SmiContext = System.Object; #endif @@ -3174,7 +3174,7 @@ private static SqlMoney GetSqlMoney_Unchecked(SmiEventSink_Default sink, ITypedG long temp = getters.GetInt64(sink, ordinal); sink.ProcessMessagesAndThrow(); -#if NETCOREAPP && NET7_0_OR_GREATER +#if NET7_0_OR_GREATER return SqlMoney.FromTdsValue(temp); #else return SqlTypeWorkarounds.SqlMoneyCtor(temp, 1 /* ignored */ ); diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBuffer.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBuffer.cs index 31678a3107..71934c5e8a 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBuffer.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBuffer.cs @@ -886,7 +886,7 @@ internal SqlMoney SqlMoney { return SqlMoney.Null; } -#if NETCOREAPP && NET7_0_OR_GREATER +#if NET7_0_OR_GREATER return SqlMoney.FromTdsValue(_value._int64); #else return SqlTypeWorkarounds.SqlMoneyCtor(_value._int64, 1/*ignored*/); diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommandBuilder.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommandBuilder.cs index 90546993a6..e256dde95c 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommandBuilder.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommandBuilder.cs @@ -256,8 +256,6 @@ public static void DeriveParameters(SqlCommand command) } #if NETFRAMEWORK TdsParser bestEffortCleanupTarget = null; -#endif -#if !NET6_0_OR_GREATER RuntimeHelpers.PrepareConstrainedRegions(); #endif try diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionString.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionString.cs index 73de1ad4f7..e9af2b8bf5 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionString.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionString.cs @@ -836,7 +836,7 @@ internal static Dictionary GetParseSynonyms() { int count = SqlConnectionStringBuilder.KeywordsCount + SynonymCount; -#if !NETFRAMEWORK +#if NET6_0_OR_GREATER count += SqlConnectionStringBuilder.DeprecatedKeywordsCount + DeprecatedSynonymCount; #endif synonyms = new Dictionary(count, StringComparer.OrdinalIgnoreCase) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionStringBuilder.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionStringBuilder.cs index c9f9fd2912..3abb275a9f 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionStringBuilder.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionStringBuilder.cs @@ -638,7 +638,7 @@ private void SetPoolBlockingPeriodValue(PoolBlockingPeriod value) private Exception UnsupportedKeyword(string keyword) { -#if !NETFRAMEWORK +#if NET6_0_OR_GREATER for (int index = 0; index < s_notSupportedKeywords.Length; index++) { if (string.Equals(keyword, s_notSupportedKeywords[index], StringComparison.OrdinalIgnoreCase)) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependency.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependency.cs index 401cde2fa2..0b882bc02c 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependency.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependency.cs @@ -629,7 +629,7 @@ internal static bool Start(string connectionString, string queue, bool useDefaul string database = null; string service = null; bool appDomainStart = false; -#if !NET6_0_OR_GREATER +#if NETFRAMEWORK RuntimeHelpers.PrepareConstrainedRegions(); #endif try @@ -775,7 +775,7 @@ internal static bool Stop(string connectionString, string queue, bool useDefault if (useDefaults) { bool appDomainStop = false; -#if !NET6_0_OR_GREATER +#if NETFRAMEWORK RuntimeHelpers.PrepareConstrainedRegions(); #endif try diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependencyUtils.AssemblyLoadContext.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependencyUtils.AssemblyLoadContext.cs index c3f82f0047..34052c3a9d 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependencyUtils.AssemblyLoadContext.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependencyUtils.AssemblyLoadContext.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 NETCOREAPP +#if NET6_0_OR_GREATER using System; using System.Reflection; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependencyUtils.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependencyUtils.cs index 3aa1697d03..c3a0bb1492 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependencyUtils.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDependencyUtils.cs @@ -107,7 +107,7 @@ private SqlDependencyPerAppDomainDispatcher() } } -#if NETCOREAPP +#if NET6_0_OR_GREATER partial void SubscribeToAppDomainUnload(); partial void SubscribeToAssemblyLoadContextUnload(); diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlParameter.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlParameter.cs index ee3a09c17a..a7c7fa58e1 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlParameter.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlParameter.cs @@ -844,7 +844,7 @@ public override string SourceColumn /// [ResCategory("DataCategory_Update")] -#if !NETFRAMEWORK +#if NET6_0_OR_GREATER [ResDescription(StringsHelper.ResourceNames.SqlParameter_SourceColumnNullMapping)] #endif public override bool SourceColumnNullMapping diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserSafeHandles.Windows.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserSafeHandles.Windows.cs index 8d276cd285..dba1ec788c 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserSafeHandles.Windows.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserSafeHandles.Windows.cs @@ -164,7 +164,7 @@ internal SNIHandle( string hostNameInCertificate) : base(IntPtr.Zero, true) { -#if !NET6_0_OR_GREATER +#if NETFRAMEWORK RuntimeHelpers.PrepareConstrainedRegions(); #endif try diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs index 17729a4cc9..4aadbee4bd 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsParserStateObject.cs @@ -976,7 +976,7 @@ internal bool TryProcessHeader() _inBuff[_inBytesUsed + TdsEnums.HEADER_LEN_FIELD_OFFSET + 1]) - _inputHeaderLen; _spid = _inBuff[_inBytesUsed + TdsEnums.SPID_OFFSET] << 8 | _inBuff[_inBytesUsed + TdsEnums.SPID_OFFSET + 1]; -#if !NETFRAMEWORK +#if NET6_0_OR_GREATER SqlClientEventSource.Log.TryAdvancedTraceEvent("TdsParserStateObject.TryProcessHeader | ADV | State Object Id {0}, Client Connection Id {1}, Server process Id (SPID) {2}", _objectID, _parser?.Connection?.ClientConnectionId, _spid); #endif _inBytesUsed += _inputHeaderLen; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsValueSetter.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsValueSetter.cs index dc797ced8e..6b05698972 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsValueSetter.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsValueSetter.cs @@ -587,7 +587,7 @@ internal void SetDateTime(DateTime value) if (SqlDbType.DateTime2 == _metaData.SqlDbType) { long time = value.TimeOfDay.Ticks / TdsEnums.TICKS_FROM_SCALE[_metaData.Scale]; -#if NETCOREAPP +#if NET6_0_OR_GREATER Span result_time = stackalloc byte[8]; BinaryPrimitives.WriteInt64LittleEndian(result_time, time); _stateObj.WriteByteSpan(result_time.Slice(0, (int)_metaData.MaxLength - 3)); @@ -595,7 +595,7 @@ internal void SetDateTime(DateTime value) _stateObj.WriteByteArray(BitConverter.GetBytes(time), (int)_metaData.MaxLength - 3, 0); #endif } -#if NETCOREAPP +#if NET6_0_OR_GREATER Span result_date = stackalloc byte[4]; BinaryPrimitives.WriteInt32LittleEndian(result_date, days); _stateObj.WriteByteSpan(result_date.Slice(0, 3)); @@ -612,7 +612,7 @@ internal void SetGuid(Guid value) Debug.Assert( SmiXetterAccessMap.IsSetterAccessValid(_metaData, SmiXetterTypeCode.XetGuid)); -#if NETCOREAPP +#if NET6_0_OR_GREATER Span bytes = stackalloc byte[16]; value.TryWriteBytes(bytes); @@ -631,7 +631,7 @@ internal void SetGuid(Guid value) _stateObj.WriteByte((byte)_metaData.MaxLength); } -#if NETCOREAPP +#if NET6_0_OR_GREATER _stateObj.WriteByteSpan(bytes); #else _stateObj.WriteByteArray(bytes, bytes.Length, 0); @@ -659,7 +659,7 @@ internal void SetTimeSpan(TimeSpan value) _stateObj.WriteByte(length); } long time = value.Ticks / TdsEnums.TICKS_FROM_SCALE[scale]; -#if NETCOREAPP +#if NET6_0_OR_GREATER Span result_time = stackalloc byte[8]; BinaryPrimitives.WriteInt64LittleEndian(result_time, time); _stateObj.WriteByteSpan(result_time.Slice(0, length)); @@ -696,7 +696,7 @@ internal void SetDateTimeOffset(DateTimeOffset value) int days = utcDateTime.Subtract(DateTime.MinValue).Days; short offset = (short)value.Offset.TotalMinutes; -#if NETCOREAPP +#if NET6_0_OR_GREATER // In TDS protocol: // https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-tds/786f5b8a-f87d-4980-9070-b9b7274c681d // diff --git a/src/Microsoft.Data.SqlClient/src/Resources/StringsHelper.cs b/src/Microsoft.Data.SqlClient/src/Resources/StringsHelper.cs index 3f003c081c..d1b736f595 100644 --- a/src/Microsoft.Data.SqlClient/src/Resources/StringsHelper.cs +++ b/src/Microsoft.Data.SqlClient/src/Resources/StringsHelper.cs @@ -63,7 +63,7 @@ public static string GetString(string res, params object[] args) } } -#if !NETFRAMEWORK +#if NET6_0_OR_GREATER // This method is used to decide if we need to append the exception message parameters to the message when calling Strings.Format. // by default it returns false. // Native code generators can replace the value this returns based on user input at the time of native code generation. diff --git a/src/Microsoft.Data.SqlClient/src/System/Diagnostics/CodeAnalysis.cs b/src/Microsoft.Data.SqlClient/src/System/Diagnostics/CodeAnalysis.cs index 1c021b459a..aaca20a34d 100644 --- a/src/Microsoft.Data.SqlClient/src/System/Diagnostics/CodeAnalysis.cs +++ b/src/Microsoft.Data.SqlClient/src/System/Diagnostics/CodeAnalysis.cs @@ -5,7 +5,7 @@ namespace System.Diagnostics.CodeAnalysis { -#if !NET6_0_OR_GREATER +#if NETFRAMEWORK [AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = true, Inherited = false)] internal sealed class MemberNotNullAttribute : Attribute { diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlErrorTest.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlErrorTest.cs index bce79cb6d1..ee05379870 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlErrorTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlErrorTest.cs @@ -16,7 +16,7 @@ public class SqlErrorTest "Connecting to a mirrored SQL Server instance using the MultiSubnetFailover connection option is not supported."; private const byte FATAL_ERROR_CLASS = 20; -#if !NET50_OR_LATER +#if NETFRAMEWORK [Fact] public static void SqlErrorSerializationTest() { diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlExceptionTest.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlExceptionTest.cs index 204ab379c1..85d3a02fb1 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlExceptionTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlExceptionTest.cs @@ -33,7 +33,7 @@ public void SerializationTest() Assert.Equal(e.StackTrace, sqlEx.StackTrace); } -#if !NET6_0_OR_GREATER +#if NETFRAMEWORK [Fact] [ActiveIssue("12161", TestPlatforms.AnyUnix)] public static void SqlExcpetionSerializationTest() diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs index 06209e1ad2..e50a202605 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs @@ -492,8 +492,8 @@ public static bool IsSupportingDistributedTransactions() public static bool IsNotUsingManagedSNIOnWindows() => !UseManagedSNIOnWindows; public static bool IsUsingNativeSNI() => -#if !NETFRAMEWORK - DataTestUtility.IsNotUsingManagedSNIOnWindows(); +#if NET6_0_OR_GREATER + IsNotUsingManagedSNIOnWindows(); #else true; #endif diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/InstanceNameTest/InstanceNameTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/InstanceNameTest/InstanceNameTest.cs index aa72bb6f5b..61474ece7f 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/InstanceNameTest/InstanceNameTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/InstanceNameTest/InstanceNameTest.cs @@ -86,7 +86,7 @@ public static void ConnectManagedWithInstanceNameTest(bool useMultiSubnetFailove } } -#if NETCOREAPP +#if NET6_0_OR_GREATER [ActiveIssue("27824")] // When specifying instance name and port number, this method call always returns false [ConditionalFact(nameof(IsSPNPortNumberTestForTCP))] public static void PortNumberInSPNTestForTCP() diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/RetryLogic/RetryLogicConfigHelper.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/RetryLogic/RetryLogicConfigHelper.cs index 7162c4dcaa..21370c08e7 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/RetryLogic/RetryLogicConfigHelper.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/RetryLogic/RetryLogicConfigHelper.cs @@ -73,7 +73,7 @@ public static object CreateLoader(RetryLogicConfigs cnnConfig, RetryLogicConfigs public static void ApplyContextSwitchByManager(string name, bool value) { -#if NETCOREAPP +#if NET6_0_OR_GREATER var appCtxType = s_sqlClientAssembly.GetType(AppCtxCfgTypeName); var appCtxObj = Activator.CreateInstance(appCtxType); SetValue(appCtxObj, appCtxType, "Value", string.Concat(name, "=", value)); From 035aec1ab54d8624eb194e4557826346a19d239a Mon Sep 17 00:00:00 2001 From: Erik Ejlskov Jensen Date: Tue, 7 May 2024 13:16:54 +0200 Subject: [PATCH 2/3] Remove NET7_0 usage --- .../src/Common/src/Interop/Windows/Interop.Libraries.cs | 2 +- .../netcore/src/Microsoft/Data/SqlClient/SNI/SNICommon.cs | 4 ++-- .../netcore/src/Microsoft/Data/SqlClient/SNI/SNIProxy.cs | 2 +- .../netcore/src/Microsoft/Data/SqlClient/SqlDataReader.cs | 2 +- .../netcore/src/Microsoft/Data/SqlClient/TdsParser.cs | 8 ++++---- .../Data/SqlClient/TdsParserStateObjectManaged.cs | 2 +- .../Data/SqlClient/SSPI/NegotiateSSPIContextProvider.cs | 2 +- .../src/Microsoft/Data/SqlClient/Server/ValueUtilsSmi.cs | 4 ++-- .../src/Microsoft/Data/SqlClient/SqlBuffer.cs | 2 +- .../tests/ManualTests/DataCommon/DataTestUtility.cs | 2 +- .../SQL/TransactionTest/DistributedTransactionTest.cs | 2 +- 11 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/Interop.Libraries.cs b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/Interop.Libraries.cs index 40308195e7..f3c5526e0f 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/Interop.Libraries.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Common/src/Interop/Windows/Interop.Libraries.cs @@ -9,7 +9,7 @@ internal static partial class Libraries internal const string Crypt32 = "crypt32.dll"; internal const string Kernel32 = "kernel32.dll"; internal const string NtDll = "ntdll.dll"; -#if !NET7_0_OR_GREATER +#if !NET8_0_OR_GREATER internal const string SspiCli = "sspicli.dll"; #endif } diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNICommon.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNICommon.cs index 9ccc98a779..2e5d3fd815 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNICommon.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNICommon.cs @@ -190,7 +190,7 @@ internal static bool ValidateSslServerCertificate(string targetServerName, X509C if (policyErrors.HasFlag(SslPolicyErrors.RemoteCertificateNameMismatch)) { -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER X509Certificate2 cert2 = cert as X509Certificate2; if (!cert2.MatchesHostname(targetServerName)) { @@ -297,7 +297,7 @@ internal static bool ValidateSslServerCertificate(X509Certificate clientCert, X5 if (policyErrors.HasFlag(SslPolicyErrors.RemoteCertificateNameMismatch)) { -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER X509Certificate2 s_cert = serverCert as X509Certificate2; X509Certificate2 c_cert = clientCert as X509Certificate2; diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIProxy.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIProxy.cs index ce3b9dd26b..e71b04e155 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIProxy.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNIProxy.cs @@ -25,7 +25,7 @@ internal class SNIProxy private static readonly SNIProxy s_singleton = new SNIProxy(); internal static SNIProxy Instance => s_singleton; -#if !NET7_0_OR_GREATER +#if !NET8_0_OR_GREATER /// /// Generate SSPI context /// diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlDataReader.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlDataReader.cs index 5eb7d7cdeb..c538483fc8 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlDataReader.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlDataReader.cs @@ -1353,7 +1353,7 @@ override public string GetName(int i) } /// -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER [return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicFields)] #endif override public Type GetProviderSpecificFieldType(int i) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs index a2e510dd01..05308fde7b 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs @@ -6146,7 +6146,7 @@ internal bool TryReadSqlValue(SqlBuffer value, SqlMetaDataPriv md, int length, T } else { -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER value.SqlBinary = SqlBinary.WrapBytes(b); #else value.SqlBinary = SqlTypeWorkarounds.SqlBinaryCtor(b, true); // doesn't copy the byte array @@ -6443,7 +6443,7 @@ internal bool TryReadSqlValueInternal(SqlBuffer value, byte tdsType, int length, { return false; } -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER value.SqlBinary = SqlBinary.WrapBytes(b); #else value.SqlBinary = SqlTypeWorkarounds.SqlBinaryCtor(b, true); @@ -7315,7 +7315,7 @@ internal byte[] SerializeSqlDecimal(SqlDecimal d, TdsParserStateObject stateObj) Span data = stackalloc uint[4]; -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER d.WriteTdsValue(data); #else SqlTypeWorkarounds.SqlDecimalExtractData(d, out data[0], out data[1], out data[2], out data[3]); @@ -7344,7 +7344,7 @@ internal void WriteSqlDecimal(SqlDecimal d, TdsParserStateObject stateObj) stateObj.WriteByte(0); Span data = stackalloc uint[4]; -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER d.WriteTdsValue(data); #else SqlTypeWorkarounds.SqlDecimalExtractData(d, out data[0], out data[1], out data[2], out data[3]); diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs index 7d879ae4d5..b912ea9f09 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs @@ -408,7 +408,7 @@ private SNIHandle GetSessionSNIHandleHandleOrThrow() private void ThrowClosedConnection() => throw ADP.ClosedConnectionError(); internal override SSPIContextProvider CreateSSPIContextProvider() -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER => new NegotiateSSPIContextProvider(); #else => new ManagedSSPIContextProvider(); diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/NegotiateSSPIContextProvider.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/NegotiateSSPIContextProvider.cs index bc11cf29c9..2380693ef9 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/NegotiateSSPIContextProvider.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SSPI/NegotiateSSPIContextProvider.cs @@ -1,4 +1,4 @@ -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER using System; using System.Text; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/ValueUtilsSmi.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/ValueUtilsSmi.cs index da931ae53f..7dd4abd7c1 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/ValueUtilsSmi.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/ValueUtilsSmi.cs @@ -3174,7 +3174,7 @@ private static SqlMoney GetSqlMoney_Unchecked(SmiEventSink_Default sink, ITypedG long temp = getters.GetInt64(sink, ordinal); sink.ProcessMessagesAndThrow(); -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER return SqlMoney.FromTdsValue(temp); #else return SqlTypeWorkarounds.SqlMoneyCtor(temp, 1 /* ignored */ ); @@ -3658,7 +3658,7 @@ private static void SetSqlMoney_Unchecked(SmiEventSink_Default sink, ITypedSette sink.ProcessMessagesAndThrow(); } -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER setters.SetInt64(sink, ordinal, value.GetTdsValue()); #else setters.SetInt64(sink, ordinal, SqlTypeWorkarounds.SqlMoneyToSqlInternalRepresentation(value)); diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBuffer.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBuffer.cs index 71934c5e8a..f28bf6033b 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBuffer.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBuffer.cs @@ -886,7 +886,7 @@ internal SqlMoney SqlMoney { return SqlMoney.Null; } -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER return SqlMoney.FromTdsValue(_value._int64); #else return SqlTypeWorkarounds.SqlMoneyCtor(_value._int64, 1/*ignored*/); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs index e50a202605..f826f96594 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs @@ -478,7 +478,7 @@ public static bool IsTargetReadyForAeWithKeyStore() public static bool IsSupportingDistributedTransactions() { -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER return OperatingSystem.IsWindows() && System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture != System.Runtime.InteropServices.Architecture.X86 && IsNotAzureServer(); #elif NETFRAMEWORK return IsNotAzureServer(); diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/TransactionTest/DistributedTransactionTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/TransactionTest/DistributedTransactionTest.cs index dc04ea56ae..658104e193 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/TransactionTest/DistributedTransactionTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/TransactionTest/DistributedTransactionTest.cs @@ -8,7 +8,7 @@ using System.Transactions; using Xunit; -#if NET7_0_OR_GREATER +#if NET8_0_OR_GREATER namespace Microsoft.Data.SqlClient.ManualTesting.Tests { From 5f70372ef4b6c514d07bb61a91bdaa346a04782e Mon Sep 17 00:00:00 2001 From: Erik Ejlskov Jensen Date: Tue, 7 May 2024 13:30:40 +0200 Subject: [PATCH 3/3] Missed some --- .../Data/SqlClient/SqlConnectionFactory.AssemblyLoadContext.cs | 2 +- .../src/Microsoft/Data/SqlClient/SqlConnectionString.cs | 2 +- .../src/Microsoft/Data/SqlClient/SqlInternalConnection.cs | 2 +- .../ManualTests/SQL/DataReaderTest/DataReaderStreamsTest.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionFactory.AssemblyLoadContext.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionFactory.AssemblyLoadContext.cs index 38411594af..230b7ae5fc 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionFactory.AssemblyLoadContext.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionFactory.AssemblyLoadContext.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 NETCOREAPP +#if NET6_0_OR_GREATER using System; using System.Reflection; diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionString.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionString.cs index e9af2b8bf5..bbcf46d727 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionString.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnectionString.cs @@ -1024,7 +1024,7 @@ internal ApplicationIntent ConvertValueToApplicationIntent() // ArgumentException and other types are raised as is (no wrapping) } -#if NETCOREAPP +#if NET6_0_OR_GREATER internal void ThrowUnsupportedIfKeywordSet(string keyword) { if (ContainsKey(keyword)) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlInternalConnection.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlInternalConnection.cs index 25e1808e56..401815cf94 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlInternalConnection.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlInternalConnection.cs @@ -27,7 +27,7 @@ internal abstract class SqlInternalConnection : DbConnectionInternal private bool _isGlobalTransactionEnabledForServer; // Whether Global Transactions are enabled for this Azure SQL DB Server private static readonly Guid s_globalTransactionTMID = new("1c742caf-6680-40ea-9c26-6b6846079764"); // ID of the Non-MSDTC, Azure SQL DB Transaction Manager -#if NETCOREAPP +#if NET6_0_OR_GREATER internal SqlCommand.ExecuteReaderAsyncCallContext CachedCommandExecuteReaderAsyncContext; internal SqlCommand.ExecuteNonQueryAsyncCallContext CachedCommandExecuteNonQueryAsyncContext; internal SqlCommand.ExecuteXmlReaderAsyncCallContext CachedCommandExecuteXmlReaderAsyncContext; diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataReaderTest/DataReaderStreamsTest.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataReaderTest/DataReaderStreamsTest.cs index 3f16a3a138..3902f812fc 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataReaderTest/DataReaderStreamsTest.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataReaderTest/DataReaderStreamsTest.cs @@ -472,7 +472,7 @@ public static void InvalidCastExceptionStream(CommandBehavior behavior, Accessor } } -#if NETCOREAPP +#if NET6_0_OR_GREATER [ConditionalFact(typeof(DataTestUtility),nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))] public static async void ReadAsyncContentsCompletes() {