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 bb77ffba3e..baa69674b8 100644
--- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj
+++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj
@@ -269,6 +269,15 @@
Microsoft\Data\SqlClient\Reliability\AppConfigManager.cs
+
+ Microsoft\Data\SqlClient\Reliability\IAppContextSwitchOverridesSection.cs
+
+
+ Microsoft\Data\SqlClient\Reliability\ISqlConfigurableRetryCommandSection.cs
+
+
+ Microsoft\Data\SqlClient\Reliability\ISqlConfigurableRetryConnectionSection.cs
+
Microsoft\Data\SqlClient\Reliability\SqlRetryingEventArgs.cs
@@ -696,7 +705,6 @@
-
diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryLogicManager.NetCoreApp.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryLogicManager.NetCoreApp.cs
deleted file mode 100644
index fc0e4c80a3..0000000000
--- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryLogicManager.NetCoreApp.cs
+++ /dev/null
@@ -1,112 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Reflection;
-using System.Runtime.Loader;
-
-namespace Microsoft.Data.SqlClient
-{
- ///
- /// Configurable retry logic manager
- ///
- internal sealed partial class SqlConfigurableRetryLogicLoader
- {
- #region Type resolution
- ///
- /// Performs a case-sensitive search to resolve the specified type name
- /// and its related assemblies in default assembly load context if they aren't loaded yet.
- ///
- /// Resolved type if it could resolve the type; otherwise, the `SqlConfigurableRetryFactory` type.
- private static Type LoadType(string fullyQualifiedName)
- {
- string methodName = nameof(LoadType);
- SqlClientEventSource.Log.TryTraceEvent(" Entry point.", TypeName, methodName);
-
- var result = Type.GetType(fullyQualifiedName, AssemblyResolver, TypeResolver);
- if (result != null)
- {
- SqlClientEventSource.Log.TryTraceEvent(" The '{2}' type is resolved.",
- TypeName, methodName, result.FullName);
- }
- else
- {
- result = typeof(SqlConfigurableRetryFactory);
- SqlClientEventSource.Log.TryTraceEvent(" Couldn't resolve the requested type by '{2}'; The internal `{3}` type is returned.",
- TypeName, methodName, fullyQualifiedName, result.FullName);
- }
- SqlClientEventSource.Log.TryTraceEvent(" Exit point.", TypeName, methodName);
- return result;
- }
-
- ///
- /// If the caller does not have sufficient permissions to read the specified file,
- /// no exception is thrown and the method returns null regardless of the existence of path.
- ///
- private static string MakeFullPath(string directory, string assemblyName, string extension = ".dll")
- {
- string methodName = nameof(MakeFullPath);
- SqlClientEventSource.Log.TryTraceEvent(" Looking for '{2}' assembly in '{3}' directory."
- , TypeName, methodName, assemblyName, directory);
- string fullPath = Path.Combine(directory, assemblyName);
- fullPath = string.IsNullOrEmpty(Path.GetExtension(fullPath)) ? fullPath + extension : fullPath;
- SqlClientEventSource.Log.TryTraceEvent(" Looking for '{2}' assembly by '{3}' full path."
- , TypeName, methodName, assemblyName, fullPath);
- return File.Exists(fullPath) ? fullPath : null;
- }
-
- private static Assembly AssemblyResolver(AssemblyName arg)
- {
- string methodName = nameof(AssemblyResolver);
-
- string fullPath = MakeFullPath(Environment.CurrentDirectory, arg.Name);
- SqlClientEventSource.Log.TryTraceEvent(" Looking for '{2}' assembly by '{3}' full path."
- , TypeName, methodName, arg, fullPath);
-
- return fullPath == null ? null : AssemblyLoadContext.Default.LoadFromAssemblyPath(fullPath);
- }
-
- private static Type TypeResolver(Assembly arg1, string arg2, bool arg3)
- {
- IEnumerable types = arg1?.ExportedTypes;
- Type result = null;
- if (types != null)
- {
- foreach (Type type in types)
- {
- if (type.FullName == arg2)
- {
- if (result != null)
- {
- throw new InvalidOperationException("Sequence contains more than one matching element");
- }
- result = type;
- }
- }
- }
- if (result == null)
- {
- throw new InvalidOperationException("Sequence contains no matching element");
- }
- return result;
- }
-
- ///
- /// Load assemblies on request.
- ///
- private static Assembly Default_Resolving(AssemblyLoadContext arg1, AssemblyName arg2)
- {
- string methodName = nameof(Default_Resolving);
-
- string target = MakeFullPath(Environment.CurrentDirectory, arg2.Name);
- SqlClientEventSource.Log.TryTraceEvent(" Looking for '{2}' assembly that is requested by '{3}' ALC from '{4}' path."
- , TypeName, methodName, arg2, arg1, target);
-
- return target == null ? null : arg1.LoadFromAssemblyPath(target);
- }
- #endregion
- }
-}
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 e5840b17a3..c4a85e413f 100644
--- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj
+++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj
@@ -445,6 +445,15 @@
Microsoft\Data\SqlClient\Reliability\AppConfigManager.cs
+
+ Microsoft\Data\SqlClient\Reliability\IAppContextSwitchOverridesSection.cs
+
+
+ Microsoft\Data\SqlClient\Reliability\ISqlConfigurableRetryCommandSection.cs
+
+
+ Microsoft\Data\SqlClient\Reliability\ISqlConfigurableRetryConnectionSection.cs
+
Microsoft\Data\SqlClient\Reliability\SqlRetryingEventArgs.cs
@@ -863,7 +872,6 @@
-
diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryLogicManager.LoadType.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryLogicManager.LoadType.cs
deleted file mode 100644
index 922006b47f..0000000000
--- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryLogicManager.LoadType.cs
+++ /dev/null
@@ -1,30 +0,0 @@
-// Licensed to the .NET Foundation under one or more agreements.
-// The .NET Foundation licenses this file to you under the MIT license.
-// See the LICENSE file in the project root for more information.
-
-using System;
-using System.Reflection;
-
-namespace Microsoft.Data.SqlClient
-{
- ///
- /// Configurable retry logic loader
- ///
- internal sealed partial class SqlConfigurableRetryLogicLoader
- {
- ///
- /// Performs a case-sensitive search to resolve the specified type name.
- ///
- ///
- /// Resolved type if it could resolve the type; otherwise, the `SqlConfigurableRetryFactory` type.
- private static Type LoadType(string fullyQualifiedName)
- {
- string methodName = nameof(LoadType);
-
- var result = Type.GetType(fullyQualifiedName);
- SqlClientEventSource.Log.TryTraceEvent(" The '{2}' type is resolved."
- , TypeName, methodName, result?.FullName);
- return result != null ? result : typeof(SqlConfigurableRetryFactory);
- }
- }
-}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/IAppContextSwitchOverridesSection.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/IAppContextSwitchOverridesSection.cs
new file mode 100644
index 0000000000..6f75b9f335
--- /dev/null
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/IAppContextSwitchOverridesSection.cs
@@ -0,0 +1,11 @@
+// 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.
+
+namespace Microsoft.Data.SqlClient
+{
+ internal interface IAppContextSwitchOverridesSection
+ {
+ string Value { get; set; }
+ }
+}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/ISqlConfigurableRetryCommandSection.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/ISqlConfigurableRetryCommandSection.cs
new file mode 100644
index 0000000000..3f7c154312
--- /dev/null
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/ISqlConfigurableRetryCommandSection.cs
@@ -0,0 +1,11 @@
+// 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.
+
+namespace Microsoft.Data.SqlClient
+{
+ internal interface ISqlConfigurableRetryCommandSection : ISqlConfigurableRetryConnectionSection
+ {
+ string AuthorizedSqlCondition { get; set; }
+ }
+}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/ISqlConfigurableRetryConnectionSection.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/ISqlConfigurableRetryConnectionSection.cs
new file mode 100644
index 0000000000..51f92bd3ba
--- /dev/null
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/ISqlConfigurableRetryConnectionSection.cs
@@ -0,0 +1,25 @@
+// 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;
+
+namespace Microsoft.Data.SqlClient
+{
+ internal interface ISqlConfigurableRetryConnectionSection
+ {
+ TimeSpan DeltaTime { get; set; }
+
+ TimeSpan MaxTimeInterval { get; set; }
+
+ TimeSpan MinTimeInterval { get; set; }
+
+ int NumberOfTries { get; set; }
+
+ string RetryLogicType { get; set; }
+
+ string RetryMethod { get; set; }
+
+ string TransientErrors { get; set; }
+ }
+}
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 c558744481..1dc48e8374 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
@@ -4,10 +4,15 @@
using System;
using System.Collections.Generic;
-using System.Diagnostics.CodeAnalysis;
using System.Reflection;
using System.Text.RegularExpressions;
+#if NET
+using System.Diagnostics.CodeAnalysis;
+using System.IO;
+using System.Runtime.Loader;
+#endif
+
namespace Microsoft.Data.SqlClient
{
///
@@ -15,7 +20,7 @@ namespace Microsoft.Data.SqlClient
/// This class shouldn't throw exceptions;
/// All exceptions should be handled internally and logged with Event Source.
///
- internal sealed partial class SqlConfigurableRetryLogicLoader
+ internal sealed class SqlConfigurableRetryLogicLoader
{
private const string TypeName = nameof(SqlConfigurableRetryLogicLoader);
@@ -38,18 +43,20 @@ private void AssignProviders(SqlRetryLogicBaseProvider cnnProvider = null, SqlRe
///
internal SqlRetryLogicBaseProvider CommandProvider { get; private set; }
- public SqlConfigurableRetryLogicLoader(ISqlConfigurableRetryConnectionSection connectionRetryConfigs,
- ISqlConfigurableRetryCommandSection commandRetryConfigs,
- string cnnSectionName = SqlConfigurableRetryConnectionSection.Name,
- string cmdSectionName = SqlConfigurableRetryCommandSection.Name)
+ public SqlConfigurableRetryLogicLoader(
+ ISqlConfigurableRetryConnectionSection connectionRetryConfigs,
+ ISqlConfigurableRetryCommandSection commandRetryConfigs,
+ string cnnSectionName = SqlConfigurableRetryConnectionSection.Name,
+ string cmdSectionName = SqlConfigurableRetryCommandSection.Name)
{
-#if NET
+ #if NET
// 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.
System.Runtime.Loader.AssemblyLoadContext.Default.Resolving -= Default_Resolving;
System.Runtime.Loader.AssemblyLoadContext.Default.Resolving += Default_Resolving;
-#endif
+ #endif
+
AssignProviders(connectionRetryConfigs == null ? null : CreateRetryLogicProvider(cnnSectionName, connectionRetryConfigs),
commandRetryConfigs == null ? null : CreateRetryLogicProvider(cmdSectionName, commandRetryConfigs));
}
@@ -156,10 +163,12 @@ private static SqlRetryLogicBaseProvider ResolveRetryLogicProvider(string config
}
private static object CreateInstance(
-#if NET
+ #if NET
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicParameterlessConstructor | DynamicallyAccessedMemberTypes.PublicMethods)]
-#endif
- Type type, string retryMethodName, SqlRetryLogicOption option)
+ #endif
+ Type type,
+ string retryMethodName,
+ SqlRetryLogicOption option)
{
string methodName = nameof(CreateInstance);
SqlClientEventSource.Log.TryTraceEvent(" Entry point.", TypeName, methodName);
@@ -324,5 +333,118 @@ private static ICollection SplitErrorNumberList(string list)
}
return new HashSet();
}
+
+ #region Type Resolution
+
+ #if NET
+ private static Assembly AssemblyResolver(AssemblyName arg)
+ {
+ string methodName = nameof(AssemblyResolver);
+
+ string fullPath = MakeFullPath(Environment.CurrentDirectory, arg.Name);
+ SqlClientEventSource.Log.TryTraceEvent(" Looking for '{2}' assembly by '{3}' full path."
+ , TypeName, methodName, arg, fullPath);
+
+ return fullPath == null ? null : AssemblyLoadContext.Default.LoadFromAssemblyPath(fullPath);
+ }
+
+ ///
+ /// Load assemblies on request.
+ ///
+ private static Assembly Default_Resolving(AssemblyLoadContext arg1, AssemblyName arg2)
+ {
+ string methodName = nameof(Default_Resolving);
+
+ string target = MakeFullPath(Environment.CurrentDirectory, arg2.Name);
+ SqlClientEventSource.Log.TryTraceEvent(" Looking for '{2}' assembly that is requested by '{3}' ALC from '{4}' path."
+ , TypeName, methodName, arg2, arg1, target);
+
+ return target == null ? null : arg1.LoadFromAssemblyPath(target);
+ }
+
+ ///
+ /// Performs a case-sensitive search to resolve the specified type name
+ /// and its related assemblies in default assembly load context if they aren't loaded yet.
+ ///
+ /// Resolved type if it could resolve the type; otherwise, the `SqlConfigurableRetryFactory` type.
+ private static Type LoadType(string fullyQualifiedName)
+ {
+ string methodName = nameof(LoadType);
+ SqlClientEventSource.Log.TryTraceEvent(" Entry point.", TypeName, methodName);
+
+ var result = Type.GetType(fullyQualifiedName, AssemblyResolver, TypeResolver);
+ if (result != null)
+ {
+ SqlClientEventSource.Log.TryTraceEvent(" The '{2}' type is resolved.",
+ TypeName, methodName, result.FullName);
+ }
+ else
+ {
+ result = typeof(SqlConfigurableRetryFactory);
+ SqlClientEventSource.Log.TryTraceEvent(" Couldn't resolve the requested type by '{2}'; The internal `{3}` type is returned.",
+ TypeName, methodName, fullyQualifiedName, result.FullName);
+ }
+ SqlClientEventSource.Log.TryTraceEvent(" Exit point.", TypeName, methodName);
+ return result;
+ }
+
+ ///
+ /// If the caller does not have sufficient permissions to read the specified file,
+ /// no exception is thrown and the method returns null regardless of the existence of path.
+ ///
+ private static string MakeFullPath(string directory, string assemblyName, string extension = ".dll")
+ {
+ string methodName = nameof(MakeFullPath);
+ SqlClientEventSource.Log.TryTraceEvent(" Looking for '{2}' assembly in '{3}' directory."
+ , TypeName, methodName, assemblyName, directory);
+ string fullPath = Path.Combine(directory, assemblyName);
+ fullPath = string.IsNullOrEmpty(Path.GetExtension(fullPath)) ? fullPath + extension : fullPath;
+ SqlClientEventSource.Log.TryTraceEvent(" Looking for '{2}' assembly by '{3}' full path."
+ , TypeName, methodName, assemblyName, fullPath);
+ return File.Exists(fullPath) ? fullPath : null;
+ }
+
+ private static Type TypeResolver(Assembly arg1, string arg2, bool arg3)
+ {
+ IEnumerable types = arg1?.ExportedTypes;
+ Type result = null;
+ if (types != null)
+ {
+ foreach (Type type in types)
+ {
+ if (type.FullName == arg2)
+ {
+ if (result != null)
+ {
+ throw new InvalidOperationException("Sequence contains more than one matching element");
+ }
+ result = type;
+ }
+ }
+ }
+ if (result == null)
+ {
+ throw new InvalidOperationException("Sequence contains no matching element");
+ }
+ return result;
+ }
+ #else
+ ///
+ /// Performs a case-sensitive search to resolve the specified type name.
+ ///
+ ///
+ /// Resolved type if it could resolve the type; otherwise, the `SqlConfigurableRetryFactory` type.
+ private static Type LoadType(string fullyQualifiedName)
+ {
+ string methodName = nameof(LoadType);
+
+ var result = Type.GetType(fullyQualifiedName);
+ SqlClientEventSource.Log.TryTraceEvent(" The '{2}' type is resolved."
+ , TypeName, methodName, result?.FullName);
+ return result != null ? result : typeof(SqlConfigurableRetryFactory);
+ }
+ #endif
+
+ #endregion
}
}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryLogicManager.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryLogicManager.cs
index 7871e6522f..aa20f7b845 100644
--- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryLogicManager.cs
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Reliability/SqlConfigurableRetryLogicManager.cs
@@ -86,25 +86,4 @@ internal static SqlRetryLogicBaseProvider CommandProvider
}
}
}
-
- internal interface IAppContextSwitchOverridesSection
- {
- string Value { get; set; }
- }
-
- internal interface ISqlConfigurableRetryConnectionSection
- {
- TimeSpan DeltaTime { get; set; }
- TimeSpan MaxTimeInterval { get; set; }
- TimeSpan MinTimeInterval { get; set; }
- int NumberOfTries { get; set; }
- string RetryLogicType { get; set; }
- string RetryMethod { get; set; }
- string TransientErrors { get; set; }
- }
-
- internal interface ISqlConfigurableRetryCommandSection : ISqlConfigurableRetryConnectionSection
- {
- string AuthorizedSqlCondition { get; set; }
- }
}