Skip to content

Commit 4c0f013

Browse files
authored
Remove UWP (uap) references and special cased code (#2483)
1 parent b4f38f5 commit 4c0f013

File tree

7 files changed

+19
-229
lines changed

7 files changed

+19
-229
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,9 @@
726726
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.IoControlTransferType.cs">
727727
<Link>Common\Interop\Windows\Kernel32\Interop.IoControlTransferType.cs</Link>
728728
</Compile>
729+
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.LoadLibraryEx.cs">
730+
<Link>Common\Interop\Windows\kernel32\Interop.LoadLibraryEx.cs</Link>
731+
</Compile>
729732
<Compile Include="$(CommonPath)\Interop\Windows\NtDll\Interop.FILE_FULL_EA_INFORMATION.cs">
730733
<Link>Common\Interop\Windows\NtDll\Interop.FILE_FULL_EA_INFORMATION.cs</Link>
731734
</Compile>
@@ -826,16 +829,25 @@
826829
<Compile Include="$(CommonSourceRoot)Microsoft\Data\Sql\SqlDataSourceEnumerator.Windows.cs">
827830
<Link>Microsoft\Data\Sql\SqlDataSourceEnumerator.Windows.cs</Link>
828831
</Compile>
832+
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SSPI\NativeSSPIContextProvider.cs">
833+
<Link>Microsoft\Data\SqlClient\SSPI\NativeSSPIContextProvider.cs</Link>
834+
</Compile>
829835
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\TdsParserSafeHandles.Windows.cs">
830836
<Link>Microsoft\Data\SqlClient\TdsParserSafeHandles.Windows.cs</Link>
831837
</Compile>
832838

839+
<Compile Include="Interop\SNINativeMethodWrapper.Windows.cs" />
840+
<Compile Include="Microsoft\Data\ProviderBase\DbConnectionPoolIdentity.Windows.cs" />
833841
<Compile Include="Microsoft\Data\SqlClient\LocalDBAPI.Common.cs" />
842+
<Compile Include="Microsoft\Data\SqlClient\LocalDBAPI.Windows.cs" />
834843
<Compile Include="Microsoft\Data\SqlClient\PacketHandle.Windows.cs" />
835844
<Compile Include="Microsoft\Data\SqlClient\SessionHandle.Windows.cs" />
845+
<Compile Include="Microsoft\Data\SqlClient\SNI\LocalDB.Windows.cs" />
836846
<Compile Include="Microsoft\Data\SqlClient\SqlColumnEncryptionCertificateStoreProvider.Windows.cs" />
837847
<Compile Include="Microsoft\Data\SqlClient\SqlColumnEncryptionCngProvider.Windows.cs" />
838848
<Compile Include="Microsoft\Data\SqlClient\SqlColumnEncryptionCspProvider.Windows.cs" />
849+
<Compile Include="Microsoft\Data\SqlClient\TdsParser.Windows.cs" />
850+
<Compile Include="Microsoft\Data\SqlClient\TdsParserStateObjectNative.cs" />
839851
<Compile Include="Microsoft\Data\SqlClient\TdsParserStateObjectFactory.Windows.cs" />
840852
<Compile Include="Microsoft\Data\SqlTypes\SqlFileStream.Windows.cs" />
841853
</ItemGroup>
@@ -894,31 +906,6 @@
894906
<Compile Include="Microsoft\Data\SqlClient\TdsParser.Unix.cs" />
895907
<Compile Include="Microsoft\Data\SqlClient\TdsParserStateObjectFactory.Managed.cs" />
896908
</ItemGroup>
897-
<ItemGroup Condition="'$(IsUAPAssembly)' == 'true'">
898-
<Compile Include="Microsoft\Data\ProviderBase\DbConnectionPoolIdentity.Unix.cs" />
899-
<Compile Include="Microsoft\Data\SqlClient\LocalDBAPI.uap.cs" />
900-
<Compile Include="Microsoft\Data\SqlClient\PacketHandle.Unix.cs" />
901-
<Compile Include="Microsoft\Data\SqlClient\SessionHandle.Unix.cs" />
902-
<Compile Include="Microsoft\Data\SqlClient\SNI\LocalDB.uap.cs" />
903-
<Compile Include="Microsoft\Data\SqlClient\TdsParser.Unix.cs" />
904-
<Compile Include="Microsoft\Data\SqlClient\TdsParserStateObjectFactory.Managed.cs" />
905-
</ItemGroup>
906-
907-
<!-- Assets needed on Windows but should be avoided on UAP to avoid sni.dll -->
908-
<ItemGroup Condition="'$(TargetsWindows)' == 'true' and '$(IsUAPAssembly)' != 'true'">
909-
<Compile Include="$(CommonPath)\Interop\Windows\kernel32\Interop.LoadLibraryEx.cs">
910-
<Link>Common\Interop\Windows\kernel32\Interop.LoadLibraryEx.cs</Link>
911-
</Compile>
912-
<Compile Include="$(CommonSourceRoot)Microsoft\Data\SqlClient\SSPI\NativeSSPIContextProvider.cs">
913-
<Link>Microsoft\Data\SqlClient\SSPI\NativeSSPIContextProvider.cs</Link>
914-
</Compile>
915-
<Compile Include="Interop\SNINativeMethodWrapper.Windows.cs" />
916-
<Compile Include="Microsoft\Data\ProviderBase\DbConnectionPoolIdentity.Windows.cs" />
917-
<Compile Include="Microsoft\Data\SqlClient\LocalDBAPI.Windows.cs" />
918-
<Compile Include="Microsoft\Data\SqlClient\SNI\LocalDB.Windows.cs" />
919-
<Compile Include="Microsoft\Data\SqlClient\TdsParserStateObjectNative.cs" />
920-
<Compile Include="Microsoft\Data\SqlClient\TdsParser.Windows.cs" />
921-
</ItemGroup>
922909

923910
<!-- Resources -->
924911
<ItemGroup>
@@ -947,10 +934,6 @@
947934
</ItemGroup>
948935

949936
<!-- Package References Etc -->
950-
<ItemGroup Condition="'$(OSGroup)' != 'AnyOS' AND '$(IsUAPAssembly)' == 'true'">
951-
<Reference Include="System.Collections.NonGeneric" />
952-
<Reference Include="System.Memory" />
953-
</ItemGroup>
954937
<ItemGroup Condition="'$(TargetGroup)' == 'netcoreapp'">
955938
<PackageReference Include="System.Configuration.ConfigurationManager" Version="$(SystemConfigurationConfigurationManagerVersion)" />
956939
<PackageReference Include="System.Runtime.Caching" Version="$(SystemRuntimeCachingVersion)" />

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/LocalDBAPI.uap.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SNI/LocalDB.uap.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,9 +1509,7 @@ internal SqlError ProcessSNIError(TdsParserStateObject stateObj)
15091509
SqlClientEventSource.Log.TryAdvancedTraceEvent("<sc.TdsParser.ProcessSNIError |ERR|ADV > Empty error message received from SNI. Error Message = {0}", details.errorMessage);
15101510
}
15111511

1512-
string sniContextEnumName = TdsEnums.GetSniContextEnumName(stateObj.SniContext);
1513-
1514-
string sqlContextInfo = StringsHelper.GetResourceString(sniContextEnumName);
1512+
string sqlContextInfo = StringsHelper.GetResourceString(stateObj.SniContext.ToString());
15151513
string providerRid = string.Format("SNI_PN{0}", details.provider);
15161514
string providerName = StringsHelper.GetResourceString(providerRid);
15171515
Debug.Assert(!string.IsNullOrEmpty(providerName), $"invalid providerResourceId '{providerRid}'");

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/TdsEnums.cs

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@
33
// See the LICENSE file in the project root for more information.
44

55
using System;
6-
using System.Collections.Generic;
7-
using System.ComponentModel;
86
using System.Data;
9-
using System.Diagnostics;
10-
using Microsoft.Data.Common;
117

128
namespace Microsoft.Data.SqlClient
139
{
@@ -998,47 +994,6 @@ internal enum FedAuthInfoId : byte
998994
internal const byte DATA_CLASSIFICATION_VERSION_WITHOUT_RANK_SUPPORT = 0x01;
999995
internal const byte DATA_CLASSIFICATION_VERSION_MAX_SUPPORTED = 0x02;
1000996

1001-
// Needed for UapAot, since we cannot use Enum.GetName() on SniContext.
1002-
// Enum.GetName() uses reflection, which is blocked on UapAot for internal types
1003-
// like SniContext.
1004-
internal static string GetSniContextEnumName(SniContext sniContext)
1005-
{
1006-
switch (sniContext)
1007-
{
1008-
case SniContext.Undefined:
1009-
return "Undefined";
1010-
case SniContext.Snix_Connect:
1011-
return "Snix_Connect";
1012-
case SniContext.Snix_PreLoginBeforeSuccessfulWrite:
1013-
return "Snix_PreLoginBeforeSuccessfulWrite";
1014-
case SniContext.Snix_PreLogin:
1015-
return "Snix_PreLogin";
1016-
case SniContext.Snix_LoginSspi:
1017-
return "Snix_LoginSspi";
1018-
case SniContext.Snix_ProcessSspi:
1019-
return "Snix_ProcessSspi";
1020-
case SniContext.Snix_Login:
1021-
return "Snix_Login";
1022-
case SniContext.Snix_EnableMars:
1023-
return "Snix_EnableMars";
1024-
case SniContext.Snix_AutoEnlist:
1025-
return "Snix_AutoEnlist";
1026-
case SniContext.Snix_GetMarsSession:
1027-
return "Snix_GetMarsSession";
1028-
case SniContext.Snix_Execute:
1029-
return "Snix_Execute";
1030-
case SniContext.Snix_Read:
1031-
return "Snix_Read";
1032-
case SniContext.Snix_Close:
1033-
return "Snix_Close";
1034-
case SniContext.Snix_SendRows:
1035-
return "Snix_SendRows";
1036-
default:
1037-
Debug.Fail($"Received unknown SniContext enum. Value: {sniContext}");
1038-
return null;
1039-
}
1040-
}
1041-
1042997
// TCE Related constants
1043998
internal const byte MAX_SUPPORTED_TCE_VERSION = 0x03; // max version
1044999
internal const byte MIN_TCE_VERSION_WITH_ENCLAVE_SUPPORT = 0x02; // min version with enclave support

src/Microsoft.Data.SqlClient/tests/ManualTests/DataCommon/DataTestUtility.cs

Lines changed: 6 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,19 @@
1111
using System.IO;
1212
using System.Linq;
1313
using System.Net;
14+
using System.Net.NetworkInformation;
1415
using System.Net.Sockets;
16+
using System.Runtime.InteropServices;
1517
using System.Security;
18+
using System.Security.Principal;
19+
using System.Text;
1620
using System.Threading;
1721
using System.Threading.Tasks;
22+
using Azure.Core;
23+
using Azure.Identity;
1824
using Microsoft.Data.SqlClient.TestUtilities;
1925
using Microsoft.Identity.Client;
2026
using Xunit;
21-
using System.Net.NetworkInformation;
22-
using System.Text;
23-
using System.Security.Principal;
24-
using System.Runtime.InteropServices;
25-
using Azure.Identity;
26-
using Azure.Core;
2727

2828
namespace Microsoft.Data.SqlClient.ManualTesting.Tests
2929
{
@@ -77,10 +77,6 @@ public static class DataTestUtility
7777
public const string AKVEventSourceName = "Microsoft.Data.SqlClient.AlwaysEncrypted.AzureKeyVaultProvider.EventSource";
7878
private const string ManagedNetworkingAppContextSwitch = "Switch.Microsoft.Data.SqlClient.UseManagedNetworkingOnWindows";
7979

80-
// uap constant
81-
const long APPMODEL_ERROR_NO_PACKAGE = 15700L;
82-
public static readonly bool IsRunningAsUWPApp = RunningAsUWPApp();
83-
8480
private static Dictionary<string, bool> AvailableDatabases;
8581
private static BaseEventListener TraceListener;
8682

@@ -676,10 +672,6 @@ public static string GetUserIdentityAccessToken()
676672

677673
public static bool IsAccessTokenSetup() => !string.IsNullOrEmpty(GetAccessToken());
678674

679-
public static bool IsSystemIdentityTokenSetup() => !string.IsNullOrEmpty(GetSystemIdentityAccessToken());
680-
681-
public static bool IsUserIdentityTokenSetup() => !string.IsNullOrEmpty(GetUserIdentityAccessToken());
682-
683675
public static bool IsFileStreamSetup() => !string.IsNullOrEmpty(FileStreamDirectory) && IsNotAzureServer() && IsNotAzureSynapse();
684676

685677
private static bool CheckException<TException>(Exception ex, string exceptionMessage, bool innerExceptionMustBeNull) where TException : Exception
@@ -780,58 +772,6 @@ public static TException ExpectFailure<TException>(Action actionThatFails, strin
780772
}
781773
}
782774

783-
public static TException ExpectFailure<TException, TInnerException>(Action actionThatFails, string exceptionMessage = null, string innerExceptionMessage = null, bool innerInnerExceptionMustBeNull = false) where TException : Exception where TInnerException : Exception
784-
{
785-
try
786-
{
787-
actionThatFails();
788-
Assert.Fail("ERROR: Did not get expected exception");
789-
return null;
790-
}
791-
catch (Exception ex)
792-
{
793-
if ((CheckException<TException>(ex, exceptionMessage, false)) && (CheckException<TInnerException>(ex.InnerException, innerExceptionMessage, innerInnerExceptionMustBeNull)))
794-
{
795-
return (ex as TException);
796-
}
797-
else
798-
{
799-
throw;
800-
}
801-
}
802-
}
803-
804-
public static TException ExpectFailure<TException, TInnerException, TInnerInnerException>(Action actionThatFails, string exceptionMessage = null, string innerExceptionMessage = null, string innerInnerExceptionMessage = null, bool innerInnerInnerExceptionMustBeNull = false) where TException : Exception where TInnerException : Exception where TInnerInnerException : Exception
805-
{
806-
try
807-
{
808-
actionThatFails();
809-
Assert.Fail("ERROR: Did not get expected exception");
810-
return null;
811-
}
812-
catch (Exception ex)
813-
{
814-
if ((CheckException<TException>(ex, exceptionMessage, false)) && (CheckException<TInnerException>(ex.InnerException, innerExceptionMessage, false)) && (CheckException<TInnerInnerException>(ex.InnerException.InnerException, innerInnerExceptionMessage, innerInnerInnerExceptionMustBeNull)))
815-
{
816-
return (ex as TException);
817-
}
818-
else
819-
{
820-
throw;
821-
}
822-
}
823-
}
824-
825-
public static void ExpectAsyncFailure<TException>(Func<Task> actionThatFails, string exceptionMessage = null, bool innerExceptionMustBeNull = false) where TException : Exception
826-
{
827-
ExpectFailure<AggregateException, TException>(() => actionThatFails().Wait(), null, exceptionMessage, innerExceptionMustBeNull);
828-
}
829-
830-
public static void ExpectAsyncFailure<TException, TInnerException>(Func<Task> actionThatFails, string exceptionMessage = null, string innerExceptionMessage = null, bool innerInnerExceptionMustBeNull = false) where TException : Exception where TInnerException : Exception
831-
{
832-
ExpectFailure<AggregateException, TException, TInnerException>(() => actionThatFails().Wait(), null, exceptionMessage, innerExceptionMessage, innerInnerExceptionMustBeNull);
833-
}
834-
835775
public static string GenerateObjectName()
836776
{
837777
return string.Format("TEST_{0}{1}{2}", Environment.GetEnvironmentVariable("ComputerName"), Environment.TickCount, Guid.NewGuid()).Replace('-', '_');
@@ -1093,44 +1033,5 @@ public static string GetMachineFQDN(string hostname)
10931033
}
10941034
return fqdn.ToString();
10951035
}
1096-
1097-
public static bool IsNotLocalhost()
1098-
{
1099-
// get the tcp connection string
1100-
SqlConnectionStringBuilder builder = new(DataTestUtility.TCPConnectionString);
1101-
1102-
string hostname = "";
1103-
1104-
// parse the datasource
1105-
ParseDataSource(builder.DataSource, out hostname, out _, out _);
1106-
1107-
// hostname must not be localhost, ., 127.0.0.1 nor ::1
1108-
return !(new string[] { "localhost", ".", "127.0.0.1", "::1" }).Contains(hostname.ToLowerInvariant());
1109-
1110-
}
1111-
1112-
private static bool RunningAsUWPApp()
1113-
{
1114-
if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
1115-
{
1116-
return false;
1117-
}
1118-
else
1119-
{
1120-
[DllImport("kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
1121-
static extern int GetCurrentPackageFullName(ref int packageFullNameLength, StringBuilder packageFullName);
1122-
1123-
{
1124-
int length = 0;
1125-
StringBuilder sb = new(0);
1126-
_ = GetCurrentPackageFullName(ref length, sb);
1127-
1128-
sb = new StringBuilder(length);
1129-
int result = GetCurrentPackageFullName(ref length, sb);
1130-
1131-
return result != APPMODEL_ERROR_NO_PACKAGE;
1132-
}
1133-
}
1134-
}
11351036
}
11361037
}

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/ExceptionTest/ConnectionExceptionTest.cs

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -176,25 +176,6 @@ public void NamedPipeInvalidConnStringTest()
176176
OpenBadConnection(builder.ConnectionString, invalidConnStringError);
177177
}
178178

179-
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.IsRunningAsUWPApp))]
180-
public static void LocalDBNotSupportedOnUapTest()
181-
{
182-
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(@$"server=(localdb)\{DataTestUtility.LocalDbAppName}")
183-
{
184-
IntegratedSecurity = true,
185-
ConnectTimeout = 2
186-
};
187-
188-
Assert.Throws<PlatformNotSupportedException>(() =>
189-
{
190-
using (SqlConnection conn = new SqlConnection(builder.ConnectionString))
191-
{
192-
conn.Open();
193-
}
194-
});
195-
}
196-
197-
198179
private void GenerateConnectionException(string connectionString)
199180
{
200181
using (SqlConnection sqlConnection = new SqlConnection(connectionString))

0 commit comments

Comments
 (0)