From 253ba509fa4f3a3b1c8e1128404f0e451d22b861 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Thu, 19 Mar 2026 08:57:49 -0700 Subject: [PATCH 1/2] Add a type forward to SqlAuthenticationMethod --- .../ref/Microsoft.Data.SqlClient.csproj | 3 ++ .../src/Microsoft.Data.SqlClient.csproj | 3 ++ .../netfx/ref/Microsoft.Data.SqlClient.csproj | 3 ++ .../netfx/src/Microsoft.Data.SqlClient.csproj | 3 ++ .../src/TypeForwards.Abstractions.cs | 8 +++++ .../tests/FunctionalTests/TypeForwardTests.cs | 29 +++++++++++++++++++ 6 files changed, 49 insertions(+) create mode 100644 src/Microsoft.Data.SqlClient/src/TypeForwards.Abstractions.cs create mode 100644 src/Microsoft.Data.SqlClient/tests/FunctionalTests/TypeForwardTests.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.csproj index f3d5bdc844..3215e42068 100644 --- a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.csproj @@ -31,6 +31,9 @@ + + TypeForwards.Abstractions.cs + diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index 6c54000f9c..7145dbac28 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -1023,6 +1023,9 @@ TypeForwards.netcore.cs + + TypeForwards.Abstractions.cs + diff --git a/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.csproj index 6765e009db..02ccf7356a 100644 --- a/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.csproj @@ -26,6 +26,9 @@ + + TypeForwards.Abstractions.cs + diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj index 05a4284565..8408dabc0d 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -1006,6 +1006,9 @@ System\Runtime\CompilerServices\IsExternalInit.netfx.cs + + TypeForwards.Abstractions.cs + diff --git a/src/Microsoft.Data.SqlClient/src/TypeForwards.Abstractions.cs b/src/Microsoft.Data.SqlClient/src/TypeForwards.Abstractions.cs new file mode 100644 index 0000000000..cf97e3283b --- /dev/null +++ b/src/Microsoft.Data.SqlClient/src/TypeForwards.Abstractions.cs @@ -0,0 +1,8 @@ +// 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. + +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(Microsoft.Data.SqlClient.SqlAuthenticationMethod))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(Microsoft.Data.SqlClient.SqlAuthenticationParameters))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(Microsoft.Data.SqlClient.SqlAuthenticationProvider))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(Microsoft.Data.SqlClient.SqlAuthenticationToken))] diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/TypeForwardTests.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/TypeForwardTests.cs new file mode 100644 index 0000000000..1bdfb8dbbe --- /dev/null +++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/TypeForwardTests.cs @@ -0,0 +1,29 @@ +// 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. + +using System; +using System.Reflection; +using Xunit; + +namespace Microsoft.Data.SqlClient.Tests +{ + public class TypeForwardTests + { + private static readonly Assembly s_sqlClientAssembly = typeof(SqlConnection).Assembly; + + [Theory] + [InlineData("Microsoft.Data.SqlClient.SqlAuthenticationMethod", true)] + [InlineData("Microsoft.Data.SqlClient.SqlAuthenticationParameters", false)] + [InlineData("Microsoft.Data.SqlClient.SqlAuthenticationProvider", false)] + [InlineData("Microsoft.Data.SqlClient.SqlAuthenticationToken", false)] + public void AbstractionsType_CanBeLoadedFromSqlClientAssembly(string typeName, bool isEnum) + { + // Types moved to the Abstractions assembly must remain loadable via the + // Microsoft.Data.SqlClient assembly for backward compatibility. + Type type = s_sqlClientAssembly.GetType(typeName, throwOnError: true); + Assert.NotNull(type); + Assert.Equal(isEnum, type.IsEnum); + } + } +} From 1489e2c4aaab7901e08707db2ea86ed9ade393a5 Mon Sep 17 00:00:00 2001 From: Cheena Malhotra Date: Thu, 19 Mar 2026 13:35:45 -0700 Subject: [PATCH 2/2] Address feedback --- .../src/TypeForwards.Abstractions.cs | 1 + .../{FunctionalTests => UnitTests}/TypeForwardTests.cs | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) rename src/Microsoft.Data.SqlClient/tests/{FunctionalTests => UnitTests}/TypeForwardTests.cs (72%) diff --git a/src/Microsoft.Data.SqlClient/src/TypeForwards.Abstractions.cs b/src/Microsoft.Data.SqlClient/src/TypeForwards.Abstractions.cs index cf97e3283b..f8272c5d2b 100644 --- a/src/Microsoft.Data.SqlClient/src/TypeForwards.Abstractions.cs +++ b/src/Microsoft.Data.SqlClient/src/TypeForwards.Abstractions.cs @@ -5,4 +5,5 @@ [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(Microsoft.Data.SqlClient.SqlAuthenticationMethod))] [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(Microsoft.Data.SqlClient.SqlAuthenticationParameters))] [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(Microsoft.Data.SqlClient.SqlAuthenticationProvider))] +[assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(Microsoft.Data.SqlClient.SqlAuthenticationProviderException))] [assembly: System.Runtime.CompilerServices.TypeForwardedTo(typeof(Microsoft.Data.SqlClient.SqlAuthenticationToken))] diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/TypeForwardTests.cs b/src/Microsoft.Data.SqlClient/tests/UnitTests/TypeForwardTests.cs similarity index 72% rename from src/Microsoft.Data.SqlClient/tests/FunctionalTests/TypeForwardTests.cs rename to src/Microsoft.Data.SqlClient/tests/UnitTests/TypeForwardTests.cs index 1bdfb8dbbe..8cb9811933 100644 --- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/TypeForwardTests.cs +++ b/src/Microsoft.Data.SqlClient/tests/UnitTests/TypeForwardTests.cs @@ -6,7 +6,7 @@ using System.Reflection; using Xunit; -namespace Microsoft.Data.SqlClient.Tests +namespace Microsoft.Data.SqlClient.UnitTests { public class TypeForwardTests { @@ -16,14 +16,19 @@ public class TypeForwardTests [InlineData("Microsoft.Data.SqlClient.SqlAuthenticationMethod", true)] [InlineData("Microsoft.Data.SqlClient.SqlAuthenticationParameters", false)] [InlineData("Microsoft.Data.SqlClient.SqlAuthenticationProvider", false)] + [InlineData("Microsoft.Data.SqlClient.SqlAuthenticationProviderException", false)] [InlineData("Microsoft.Data.SqlClient.SqlAuthenticationToken", false)] public void AbstractionsType_CanBeLoadedFromSqlClientAssembly(string typeName, bool isEnum) { // Types moved to the Abstractions assembly must remain loadable via the // Microsoft.Data.SqlClient assembly for backward compatibility. - Type type = s_sqlClientAssembly.GetType(typeName, throwOnError: true); + Type? type = s_sqlClientAssembly.GetType(typeName, throwOnError: true); + Assert.NotNull(type); Assert.Equal(isEnum, type.IsEnum); + + // Assert that the assembly containing the type is the Abstractions assembly. + Assert.Equal("Microsoft.Data.SqlClient.Extensions.Abstractions", type.Assembly.GetName().Name); } } }