Skip to content

Commit ab9207a

Browse files
authored
Clean up Preprocessor Directives After NET6 Removal (#2938)
1 parent 938c705 commit ab9207a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+129
-235
lines changed

src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs

+2-17
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ public static partial class SqlClientMetaDataCollectionNames
513513
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlClientMetaDataCollectionNames.xml' path='docs/members[@name="SqlClientMetaDataCollectionNames"]/StructuredTypeMembers/*' />
514514
public static readonly string StructuredTypeMembers;
515515
}
516-
#if NET6_0_OR_GREATER
516+
517517
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnectionAttestationProtocol.xml' path='docs/members[@name="SqlConnectionAttestationProtocol"]/SqlConnectionAttestationProtocol/*' />
518518
public enum SqlConnectionAttestationProtocol
519519
{
@@ -529,7 +529,7 @@ public enum SqlConnectionAttestationProtocol
529529
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnectionAttestationProtocol.xml' path='docs/members[@name="SqlConnectionAttestationProtocol"]/HGS/*' />
530530
HGS = 3
531531
}
532-
#endif
532+
533533
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnectionIPAddressPreference.xml' path='docs/members[@name="SqlConnectionIPAddressPreference"]/SqlConnectionIPAddressPreference/*' />
534534
public enum SqlConnectionIPAddressPreference
535535
{
@@ -1053,7 +1053,6 @@ public SqlConnectionStringBuilder(string connectionString) { }
10531053
[System.ComponentModel.DisplayNameAttribute("Data Source")]
10541054
[System.ComponentModel.RefreshPropertiesAttribute(System.ComponentModel.RefreshProperties.All)]
10551055
public string DataSource { get { throw null; } set { } }
1056-
#if NET6_0_OR_GREATER
10571056
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnectionStringBuilder.xml' path='docs/members[@name="SqlConnectionStringBuilder"]/AttestationProtocol/*' />
10581057
[System.ComponentModel.DisplayNameAttribute("Attestation Protocol")]
10591058
[System.ComponentModel.RefreshPropertiesAttribute(System.ComponentModel.RefreshProperties.All)]
@@ -1062,7 +1061,6 @@ public SqlConnectionStringBuilder(string connectionString) { }
10621061
[System.ComponentModel.DisplayNameAttribute("Enclave Attestation Url")]
10631062
[System.ComponentModel.RefreshPropertiesAttribute(System.ComponentModel.RefreshProperties.All)]
10641063
public string EnclaveAttestationUrl { get { throw null; } set { } }
1065-
#endif
10661064
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnectionStringBuilder.xml' path='docs/members[@name="SqlConnectionStringBuilder"]/IPAddressPreference/*'/>
10671065
[System.ComponentModel.DisplayNameAttribute("IP Address Preference")]
10681066
[System.ComponentModel.RefreshPropertiesAttribute(System.ComponentModel.RefreshProperties.All)]
@@ -1486,12 +1484,7 @@ internal SqlException() { }
14861484
public byte State { get { throw null; } }
14871485

14881486
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlException.xml' path='docs/members[@name="SqlException"]/GetObjectData/*'/>
1489-
#if NETFRAMEWORK
1490-
[System.Security.Permissions.SecurityPermissionAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Flags = System.Security.Permissions.SecurityPermissionFlag.SerializationFormatter)]
1491-
#endif
1492-
#if NET8_0_OR_GREATER
14931487
[System.Obsolete("This API supports obsolete formatter-based serialization. It should not be called or extended by application code.", DiagnosticId = "SYSLIB0051", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
1494-
#endif
14951488
public override void GetObjectData(System.Runtime.Serialization.SerializationInfo si, System.Runtime.Serialization.StreamingContext context) { }
14961489
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlException.xml' path='docs/members[@name="SqlException"]/ToString/*'/>
14971490
public override string ToString() { throw null; }
@@ -1824,18 +1817,10 @@ protected override void Dispose(bool disposing) { }
18241817
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlTransaction.xml' path='docs/members[@name="SqlTransaction"]/Rollback1/*'/>
18251818
public override void Rollback() { }
18261819
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlTransaction.xml' path='docs/members[@name="SqlTransaction"]/Rollback2/*'/>
1827-
#if NET6_0_OR_GREATER
18281820
public override void Rollback(string transactionName) { }
1829-
#else
1830-
public void Rollback(string transactionName) { }
1831-
#endif
18321821

18331822
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlTransaction.xml' path='docs/members[@name="SqlTransaction"]/Save/*'/>
1834-
#if NET6_0_OR_GREATER
18351823
public override void Save(string savePointName) { }
1836-
#else
1837-
public void Save(string savePointName) { }
1838-
#endif
18391824
}
18401825
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlRetryingEventArgs.xml' path='docs/members[@name="SqlRetryingEventArgs"]/SqlRetryingEventArgs/*' />
18411826
public sealed class SqlRetryingEventArgs : System.EventArgs

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNICommon.cs

-39
Original file line numberDiff line numberDiff line change
@@ -232,51 +232,12 @@ internal static bool ValidateSslServerCertificate(Guid connectionId, string targ
232232

233233
if (policyErrors.HasFlag(SslPolicyErrors.RemoteCertificateNameMismatch))
234234
{
235-
#if NET8_0_OR_GREATER
236235
X509Certificate2 cert2 = serverCert as X509Certificate2;
237236
if (!cert2.MatchesHostname(serverNameToValidate))
238237
{
239238
SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNICommon), EventType.ERR, "Connection Id {0}, serverNameToValidate {1}, Target Server name or HNIC does not match the Subject/SAN in Certificate.", args0: connectionId, args1: serverNameToValidate);
240239
messageBuilder.AppendLine(Strings.SQL_RemoteCertificateNameMismatch);
241240
}
242-
#else
243-
// To Do: include certificate SAN (Subject Alternative Name) check.
244-
string certServerName = serverCert.Subject.Substring(serverCert.Subject.IndexOf('=') + 1);
245-
246-
// Verify that target server name matches subject in the certificate
247-
if (serverNameToValidate.Length > certServerName.Length)
248-
{
249-
SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNICommon), EventType.ERR, "Connection Id {0}, serverNameToValidate {1}, Target Server name is of greater length than Subject in Certificate.", args0: connectionId, args1: serverNameToValidate);
250-
messageBuilder.AppendLine(Strings.SQL_RemoteCertificateNameMismatch);
251-
}
252-
else if (serverNameToValidate.Length == certServerName.Length)
253-
{
254-
// Both strings have the same length, so serverNameToValidate must be a FQDN
255-
if (!serverNameToValidate.Equals(certServerName, StringComparison.OrdinalIgnoreCase))
256-
{
257-
SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNICommon), EventType.ERR, "Connection Id {0}, serverNameToValidate {1}, Target Server name does not match Subject in Certificate.", args0: connectionId, args1: serverNameToValidate);
258-
messageBuilder.AppendLine(Strings.SQL_RemoteCertificateNameMismatch);
259-
}
260-
}
261-
else
262-
{
263-
if (string.Compare(serverNameToValidate, 0, certServerName, 0, serverNameToValidate.Length, StringComparison.OrdinalIgnoreCase) != 0)
264-
{
265-
SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNICommon), EventType.ERR, "Connection Id {0}, serverNameToValidate {1}, Target Server name does not match Subject in Certificate.", args0: connectionId, args1: serverNameToValidate);
266-
messageBuilder.AppendLine(Strings.SQL_RemoteCertificateNameMismatch);
267-
}
268-
269-
// Server name matches cert name for its whole length, so ensure that the
270-
// character following the server name is a '.'. This will avoid
271-
// having server name "ab" match "abc.corp.company.com"
272-
// (Names have different lengths, so the target server can't be a FQDN.)
273-
if (certServerName[serverNameToValidate.Length] != '.')
274-
{
275-
SqlClientEventSource.Log.TrySNITraceEvent(nameof(SNICommon), EventType.ERR, "Connection Id {0}, serverNameToValidate {1}, Target Server name does not match Subject in Certificate.", args0: connectionId, args1: serverNameToValidate);
276-
messageBuilder.AppendLine(Strings.SQL_RemoteCertificateNameMismatch);
277-
}
278-
}
279-
#endif
280241
}
281242

282243
if (messageBuilder.Length > 0)

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/SNITcpHandle.cs

-2
Original file line numberDiff line numberDiff line change
@@ -1019,11 +1019,9 @@ public override void KillConnection()
10191019

10201020
internal static void SetKeepAliveValues(ref Socket socket)
10211021
{
1022-
#if NET6_0_OR_GREATER
10231022
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
10241023
socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveInterval, 1);
10251024
socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.TcpKeepAliveTime, 30);
1026-
#endif
10271025
}
10281026
}
10291027
}

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnection.cs

-2
Original file line numberDiff line numberDiff line change
@@ -1794,13 +1794,11 @@ public override DataTable GetSchema(string collectionName, string[] restrictionV
17941794
return InnerConnection.GetSchema(ConnectionFactory, PoolGroup, this, collectionName, restrictionValues);
17951795
}
17961796

1797-
#if NET6_0_OR_GREATER
17981797
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnection.xml' path='docs/members[@name="SqlConnection"]/CanCreateBatch/*'/>
17991798
public override bool CanCreateBatch => true;
18001799

18011800
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlConnection.xml' path='docs/members[@name="SqlConnection"]/CreateDbBatch/*'/>
18021801
protected override DbBatch CreateDbBatch() => new SqlBatch(this);
1803-
#endif
18041802

18051803
private class OpenAsyncRetry
18061804
{

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlConnectionFactory.AssemblyLoadContext.cs

-4
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
#if NET6_0_OR_GREATER
6-
75
using System;
86
using System.Reflection;
97
using System.Runtime.Loader;
@@ -23,5 +21,3 @@ private void SqlConnectionFactoryAssemblyLoadContext_Unloading(AssemblyLoadConte
2321
}
2422
}
2523
}
26-
27-
#endif

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlDataReader.cs

-2
Original file line numberDiff line numberDiff line change
@@ -1369,9 +1369,7 @@ override public string GetName(int i)
13691369
}
13701370

13711371
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetProviderSpecificFieldType/*' />
1372-
#if !NETFRAMEWORK && NET8_0_OR_GREATER
13731372
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicFields)]
1374-
#endif
13751373
override public Type GetProviderSpecificFieldType(int i)
13761374
{
13771375
SqlStatistics statistics = null;

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlTransaction.cs

-8
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,7 @@ public override void Rollback()
119119
}
120120

121121
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlTransaction.xml' path='docs/members[@name="SqlTransaction"]/RollbackTransactionName/*' />
122-
#if NET6_0_OR_GREATER
123122
public override void Rollback(string transactionName)
124-
#else
125-
public void Rollback(string transactionName)
126-
#endif
127123
{
128124
using (DiagnosticTransactionScope diagnosticScope = s_diagnosticListener.CreateTransactionRollbackScope(_isolationLevel, _connection, InternalTransaction, transactionName))
129125
{
@@ -155,11 +151,7 @@ public void Rollback(string transactionName)
155151
}
156152

157153
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlTransaction.xml' path='docs/members[@name="SqlTransaction"]/Save/*' />
158-
#if NET6_0_OR_GREATER
159154
public override void Save(string savePointName)
160-
#else
161-
public void Save(string savePointName)
162-
#endif
163155
{
164156
ZombieCheck();
165157

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParser.cs

-23
Original file line numberDiff line numberDiff line change
@@ -1790,14 +1790,7 @@ internal void WriteInt(int v, TdsParserStateObject stateObj)
17901790

17911791
internal static void WriteInt(Span<byte> buffer, int value)
17921792
{
1793-
#if NET6_0_OR_GREATER
17941793
BinaryPrimitives.TryWriteInt32LittleEndian(buffer, value);
1795-
#else
1796-
buffer[0] = (byte)(value & 0xff);
1797-
buffer[1] = (byte)((value >> 8) & 0xff);
1798-
buffer[2] = (byte)((value >> 16) & 0xff);
1799-
buffer[3] = (byte)((value >> 24) & 0xff);
1800-
#endif
18011794
}
18021795

18031796
//
@@ -6455,11 +6448,7 @@ internal TdsOperationStatus TryReadSqlValue(SqlBuffer value, SqlMetaDataPriv md,
64556448
}
64566449
else
64576450
{
6458-
#if NET8_0_OR_GREATER
64596451
value.SqlBinary = SqlBinary.WrapBytes(b);
6460-
#else
6461-
value.SqlBinary = SqlTypeWorkarounds.SqlBinaryCtor(b, true); // doesn't copy the byte array
6462-
#endif
64636452
}
64646453
break;
64656454

@@ -6776,11 +6765,7 @@ internal TdsOperationStatus TryReadSqlValueInternal(SqlBuffer value, byte tdsTyp
67766765
{
67776766
return result;
67786767
}
6779-
#if NET8_0_OR_GREATER
67806768
value.SqlBinary = SqlBinary.WrapBytes(b);
6781-
#else
6782-
value.SqlBinary = SqlTypeWorkarounds.SqlBinaryCtor(b, true);
6783-
#endif
67846769

67856770
break;
67866771
}
@@ -7669,11 +7654,7 @@ internal byte[] SerializeSqlDecimal(SqlDecimal d, TdsParserStateObject stateObj)
76697654

76707655

76717656
Span<uint> data = stackalloc uint[4];
7672-
#if NET8_0_OR_GREATER
76737657
d.WriteTdsValue(data);
7674-
#else
7675-
SqlTypeWorkarounds.SqlDecimalExtractData(d, out data[0], out data[1], out data[2], out data[3]);
7676-
#endif
76777658
byte[] bytesPart = SerializeUnsignedInt(data[0], stateObj);
76787659
Buffer.BlockCopy(bytesPart, 0, bytes, current, 4);
76797660
current += 4;
@@ -7698,11 +7679,7 @@ internal void WriteSqlDecimal(SqlDecimal d, TdsParserStateObject stateObj)
76987679
stateObj.WriteByte(0);
76997680

77007681
Span<uint> data = stackalloc uint[4];
7701-
#if NET8_0_OR_GREATER
77027682
d.WriteTdsValue(data);
7703-
#else
7704-
SqlTypeWorkarounds.SqlDecimalExtractData(d, out data[0], out data[1], out data[2], out data[3]);
7705-
#endif
77067683
WriteUnsignedInt(data[0], stateObj);
77077684
WriteUnsignedInt(data[1], stateObj);
77087685
WriteUnsignedInt(data[2], stateObj);

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectManaged.cs

-4
Original file line numberDiff line numberDiff line change
@@ -408,10 +408,6 @@ private SNIHandle GetSessionSNIHandleHandleOrThrow()
408408
private void ThrowClosedConnection() => throw ADP.ClosedConnectionError();
409409

410410
internal override SSPIContextProvider CreateSSPIContextProvider()
411-
#if NET8_0_OR_GREATER
412411
=> new NegotiateSSPIContextProvider();
413-
#else
414-
=> new ManagedSSPIContextProvider();
415-
#endif
416412
}
417413
}

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/TdsParserStateObjectNative.cs

-2
Original file line numberDiff line numberDiff line change
@@ -410,13 +410,11 @@ internal override uint WaitForSSLHandShakeToComplete(out int protocolVersion)
410410
{
411411
protocolVersion = (int)SslProtocols.Tls12;
412412
}
413-
#if NET6_0_OR_GREATER
414413
else if (nativeProtocol.HasFlag(NativeProtocols.SP_PROT_TLS1_3_CLIENT) || nativeProtocol.HasFlag(NativeProtocols.SP_PROT_TLS1_3_SERVER))
415414
{
416415
/* The SslProtocols.Tls13 is supported by netcoreapp3.1 and later */
417416
protocolVersion = (int)SslProtocols.Tls13;
418417
}
419-
#endif
420418
else if (nativeProtocol.HasFlag(NativeProtocols.SP_PROT_TLS1_1_CLIENT) || nativeProtocol.HasFlag(NativeProtocols.SP_PROT_TLS1_1_SERVER))
421419
{
422420
protocolVersion = (int)SslProtocols.Tls11;

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDataReader.cs

-3
Original file line numberDiff line numberDiff line change
@@ -1572,9 +1572,6 @@ override public string GetName(int i)
15721572
}
15731573

15741574
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlDataReader.xml' path='docs/members[@name="SqlDataReader"]/GetProviderSpecificFieldType/*' />
1575-
#if !NETFRAMEWORK && NET8_0_OR_GREATER
1576-
[return: DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicProperties | DynamicallyAccessedMemberTypes.PublicFields)]
1577-
#endif
15781575
override public Type GetProviderSpecificFieldType(int i)
15791576
{
15801577
SqlStatistics statistics = null;

src/Microsoft.Data.SqlClient/src/Microsoft/Data/OperationAbortedException.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ private OperationAbortedException(string message, Exception innerException) : ba
1818
HResult = unchecked((int)0x80131936);
1919
}
2020

21-
#if NET8_0_OR_GREATER
21+
#if NET
2222
[Obsolete]
2323
#endif
2424
private OperationAbortedException(SerializationInfo info, StreamingContext context) : base(info, context)

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ActiveDirectoryAuthenticationProvider.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public override async Task<SqlAuthenticationToken> AcquireTokenAsync(SqlAuthenti
199199
*/
200200
string redirectUri = s_nativeClientRedirectUri;
201201

202-
#if NET6_0_OR_GREATER
202+
#if NET
203203
if (parameters.AuthenticationMethod != SqlAuthenticationMethod.ActiveDirectoryDeviceCodeFlow)
204204
{
205205
redirectUri = "http://localhost";
@@ -353,7 +353,7 @@ private static async Task<AuthenticationResult> AcquireTokenInteractiveDeviceFlo
353353
if (authenticationMethod == SqlAuthenticationMethod.ActiveDirectoryInteractive)
354354
{
355355
CancellationTokenSource ctsInteractive = new();
356-
#if NET6_0_OR_GREATER
356+
#if NET
357357
/*
358358
* On .NET Core, MSAL will start the system browser as a separate process. MSAL does not have control over this browser,
359359
* but once the user finishes authentication, the web page is redirected in such a way that MSAL can intercept the Uri.

0 commit comments

Comments
 (0)