From 04675062afae28ffaf188605f8abd7f4418911a0 Mon Sep 17 00:00:00 2001 From: David Engel Date: Thu, 25 Feb 2021 17:35:04 -0800 Subject: [PATCH] Fix | MARS header contains errors on .NET Framework 4.8 (#910) * MARS header errors fix --- .../src/Microsoft.Data.SqlClient.csproj | 3 + .../src/Microsoft/Data/SqlClient/TdsParser.cs | 10 +- .../netfx/src/Microsoft.Data.SqlClient.csproj | 10 +- .../AppContextDefaultValues.Defaults.cs | 34 ---- ...es.cs => LocalAppContextSwitches.netfx.cs} | 21 +-- .../Microsoft/Data/SqlClient/LocalDBAPI.cs | 2 +- .../Data/SqlClient/SqlConnectionFactory.cs | 34 +--- .../Microsoft/Data/SqlClient/SqlException.cs | 5 +- .../src/Microsoft/Data/SqlClient/TdsParser.cs | 2 +- .../netfx/src/Misc/AppContextDefaultValues.cs | 175 ------------------ .../netfx/src/Misc/ExternDll.cs | 71 ------- .../netfx/src/Misc/HResults.cs | 103 ----------- .../netfx/src/Misc/LocalAppContext.cs | 136 -------------- .../Misc/PrivilegedConfigurationManager.cs | 26 --- .../Data/SqlClient/LocalAppContextSwitches.cs | 23 +++ 15 files changed, 49 insertions(+), 606 deletions(-) delete mode 100644 src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/AppContextDefaultValues.Defaults.cs rename src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/{LocalAppContextSwitches.cs => LocalAppContextSwitches.netfx.cs} (52%) delete mode 100644 src/Microsoft.Data.SqlClient/netfx/src/Misc/AppContextDefaultValues.cs delete mode 100644 src/Microsoft.Data.SqlClient/netfx/src/Misc/HResults.cs delete mode 100644 src/Microsoft.Data.SqlClient/netfx/src/Misc/LocalAppContext.cs delete mode 100644 src/Microsoft.Data.SqlClient/netfx/src/Misc/PrivilegedConfigurationManager.cs create mode 100644 src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.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 b7bbba8abc..f5d1646cba 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -87,6 +87,9 @@ Microsoft\Data\SqlClient\AzureManagedIdentityAuthenticationProvider.cs + + Microsoft\Data\SqlClient\LocalAppContextSwitches.cs + Microsoft\Data\SqlClient\Server\ExtendedClrTypeCode.cs 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 90f5d0bf02..b35fe17226 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 @@ -2884,11 +2884,11 @@ private bool TryProcessDone(SqlCommand cmd, SqlDataReader reader, ref RunBehavio ushort status; int count; - // This is added back since removing it from here introduces regressions in Managed SNI. - // It forces SqlDataReader.ReadAsync() method to run synchronously, - // and will block the calling thread until data is fed from SQL Server. - // TODO Investigate better solution to support non-blocking ReadAsync(). - stateObj._syncOverAsync = true; + if (LocalAppContextSwitches.MakeReadAsyncBlocking) + { + // Don't retry TryProcessDone + stateObj._syncOverAsync = true; + } // status // command 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 cf8c458f2e..7ed0b1657e 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -91,6 +91,9 @@ + + Microsoft\Data\SqlClient\LocalAppContextSwitches.cs + Microsoft\Data\SqlClient\SqlClientEventSource.cs @@ -337,11 +340,10 @@ - - + @@ -426,10 +428,6 @@ - - - - diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/AppContextDefaultValues.Defaults.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/AppContextDefaultValues.Defaults.cs deleted file mode 100644 index 6f42414b2d..0000000000 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/AppContextDefaultValues.Defaults.cs +++ /dev/null @@ -1,34 +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 Microsoft.Data.SqlClient; - -namespace System -{ - internal static partial class AppContextDefaultValues - { - static partial void PopulateDefaultValuesPartial(string platformIdentifier, string profile, int version) - { - // When defining a new switch you should add it to the last known version. - // For instance, if you are adding a switch in .NET 4.6 (the release after 4.5.2) you should defined your switch - // like this: - // if (version <= 40502) ... - // This ensures that all previous versions of that platform (up-to 4.5.2) will get the old behavior by default - // NOTE: When adding a default value for a switch please make sure that the default value is added to ALL of the existing platforms! - // NOTE: When adding a new if statement for the version please ensure that ALL previous switches are enabled (ie. don't use else if) - switch (platformIdentifier) - { - case ".NETCore": - case ".NETFramework": - { - if (version <= 40702) - { - LocalAppContext.DefineSwitchDefault(LocalAppContextSwitches.MakeReadAsyncBlockingString, true); - } - break; - } - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.netfx.cs similarity index 52% rename from src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs rename to src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.netfx.cs index 4a36d86d12..1ca55ab848 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.netfx.cs @@ -7,38 +7,27 @@ namespace Microsoft.Data.SqlClient { - internal static class LocalAppContextSwitches + internal static partial class LocalAppContextSwitches { - internal const string MakeReadAsyncBlockingString = @"Switch.Microsoft.Data.SqlClient.MakeReadAsyncBlocking"; - private static int _makeReadAsyncBlocking; - public static bool MakeReadAsyncBlocking - { - [MethodImpl(MethodImplOptions.AggressiveInlining)] - get - { - return LocalAppContext.GetCachedSwitchValue(MakeReadAsyncBlockingString, ref _makeReadAsyncBlocking); - } - } - internal const string UseMinimumLoginTimeoutString = @"Switch.Microsoft.Data.SqlClient.UseOneSecFloorInTimeoutCalculationDuringLogin"; - private static int _useMinimumLoginTimeout; + private static bool _useMinimumLoginTimeout; public static bool UseMinimumLoginTimeout { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - return LocalAppContext.GetCachedSwitchValue(UseMinimumLoginTimeoutString, ref _useMinimumLoginTimeout); + return AppContext.TryGetSwitch(UseMinimumLoginTimeoutString, out _useMinimumLoginTimeout) ? _useMinimumLoginTimeout : false; } } internal const string DisableTNIRByDefaultString = @"Switch.Microsoft.Data.SqlClient.DisableTNIRByDefaultInConnectionString"; - private static int _disableTNIRByDefault; + private static bool _disableTNIRByDefault; public static bool DisableTNIRByDefault { [MethodImpl(MethodImplOptions.AggressiveInlining)] get { - return LocalAppContext.GetCachedSwitchValue(DisableTNIRByDefaultString, ref _disableTNIRByDefault); + return AppContext.TryGetSwitch(DisableTNIRByDefaultString, out _disableTNIRByDefault) ? _disableTNIRByDefault : false; } } } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/LocalDBAPI.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/LocalDBAPI.cs index c18fdda558..f1f4c955af 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/LocalDBAPI.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/LocalDBAPI.cs @@ -300,7 +300,7 @@ internal static void CreateLocalDBInstance(string instance) if (s_configurableInstances == null) { Dictionary tempConfigurableInstances = new Dictionary(StringComparer.OrdinalIgnoreCase); - object section = PrivilegedConfigurationManager.GetSection("system.data.localdb"); + object section = ConfigurationManager.GetSection("system.data.localdb"); if (section != null) // if no section just skip creation { // validate section type diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs index 2c56d89165..e2051784a3 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlConnectionFactory.cs @@ -206,44 +206,18 @@ override protected DbConnectionPoolGroupOptions CreateConnectionPoolGroupOptions return poolingOptions; } - // SxS (VSDD 545786): metadata files are opened from <.NetRuntimeFolder>\CONFIG\ - // this operation is safe in SxS because the file is opened in read-only mode and each NDP runtime accesses its own copy of the metadata - // under the runtime folder. - [ResourceExposure(ResourceScope.None)] - [ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)] override protected DbMetaDataFactory CreateMetaDataFactory(DbConnectionInternal internalConnection, out bool cacheMetaDataFactory) { Debug.Assert(internalConnection != null, "internalConnection may not be null."); - cacheMetaDataFactory = false; - if (internalConnection is SqlInternalConnectionSmi) - { - throw SQL.NotAvailableOnContextConnection(); - } - - NameValueCollection settings = (NameValueCollection)PrivilegedConfigurationManager.GetSection("Microsoft.Data.SqlClient"); - Stream XMLStream = null; - if (settings != null) - { - string[] values = settings.GetValues(_metaDataXml); - if (values != null) - { - XMLStream = ADP.GetXmlStreamFromValues(values, _metaDataXml); - } - } + Stream xmlStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Microsoft.Data.SqlClient.SqlMetaData.xml"); + cacheMetaDataFactory = true; - // if the xml was not obtained from machine.config use the embedded XML resource - if (XMLStream == null) - { - XMLStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream("Microsoft.Data.SqlClient.SqlMetaData.xml"); - cacheMetaDataFactory = true; - } - Debug.Assert(XMLStream != null, "XMLstream may not be null."); + Debug.Assert(xmlStream != null, nameof(xmlStream) + " may not be null."); - return new SqlMetaDataFactory(XMLStream, + return new SqlMetaDataFactory(xmlStream, internalConnection.ServerVersion, internalConnection.ServerVersion); //internalConnection.ServerVersionNormalized); - } override internal DbConnectionPoolGroupProviderInfo CreateConnectionPoolGroupProviderInfo(DbConnectionOptions connectionOptions) diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlException.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlException.cs index 7e4fe9f411..b4e0c7ea2c 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlException.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlException.cs @@ -19,6 +19,7 @@ public sealed class SqlException : System.Data.Common.DbException { private const string OriginalClientConnectionIdKey = "OriginalClientConnectionId"; private const string RoutingDestinationKey = "RoutingDestination"; + private const int SqlExceptionHResult = unchecked((int)0x80131904); private SqlErrorCollection _errors; [System.Runtime.Serialization.OptionalFieldAttribute(VersionAdded = 4)] @@ -26,7 +27,7 @@ public sealed class SqlException : System.Data.Common.DbException private SqlException(string message, SqlErrorCollection errorCollection, Exception innerException, Guid conId) : base(message, innerException) { - HResult = HResults.SqlException; + HResult = SqlExceptionHResult; _errors = errorCollection; _clientConnectionId = conId; } @@ -35,7 +36,7 @@ private SqlException(string message, SqlErrorCollection errorCollection, Excepti private SqlException(SerializationInfo si, StreamingContext sc) : base(si, sc) { _errors = (SqlErrorCollection)si.GetValue("Errors", typeof(SqlErrorCollection)); - HResult = HResults.SqlException; + HResult = SqlExceptionHResult; foreach (SerializationEntry siEntry in si) { if (nameof(ClientConnectionId) == siEntry.Name) diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs index 37c73dfe92..92368b17bb 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/TdsParser.cs @@ -3301,7 +3301,7 @@ private bool TryProcessDone(SqlCommand cmd, SqlDataReader reader, ref RunBehavio if (LocalAppContextSwitches.MakeReadAsyncBlocking) { - // Can't retry TryProcessDone + // Don't retry TryProcessDone stateObj._syncOverAsync = true; } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Misc/AppContextDefaultValues.cs b/src/Microsoft.Data.SqlClient/netfx/src/Misc/AppContextDefaultValues.cs deleted file mode 100644 index aea1bca453..0000000000 --- a/src/Microsoft.Data.SqlClient/netfx/src/Misc/AppContextDefaultValues.cs +++ /dev/null @@ -1,175 +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. - -// There are cases where we have multiple assemblies that are going to import this file and -// if they are going to also have InternalsVisibleTo between them, there will be a compiler warning -// that the type is found both in the source and in a referenced assembly. The compiler will prefer -// the version of the type defined in the source -// -// In order to disable the warning for this type we are disabling this warning for this entire file. -#pragma warning disable 436 - -namespace System -{ - internal static partial class AppContextDefaultValues - { - public static void PopulateDefaultValues() - { - string platformIdentifier, profile; - int version; - - ParseTargetFrameworkName(out platformIdentifier, out profile, out version); - - // Call into each library to populate their default switches - PopulateDefaultValuesPartial(platformIdentifier, profile, version); - } - - /// - /// We have this separate method for getting the parsed elements out of the TargetFrameworkName so we can - /// more easily support this on other platforms. - /// - private static void ParseTargetFrameworkName(out string identifier, out string profile, out int version) - { - string targetFrameworkMoniker = AppDomain.CurrentDomain.SetupInformation.TargetFrameworkName; - - // If we don't have a TFM then we should default to the 4.0 behavior where all quirks are turned on. - if (!TryParseFrameworkName(targetFrameworkMoniker, out identifier, out version, out profile)) - { -#if FEATURE_CORECLR - if (CompatibilitySwitches.UseLatestBehaviorWhenTFMNotSpecified) - { - // If we want to use the latest behavior it is enough to set the value of the switch to string.Empty. - // When the get to the caller of this method (PopulateDefaultValuesPartial) we are going to use the - // identifier we just set to decide which switches to turn on. By having an empty string as the - // identifier we are simply saying -- don't turn on any switches, and we are going to get the latest - // behavior for all the switches - identifier = string.Empty; - } - else -#endif - { - identifier = ".NETFramework"; - version = 40000; - profile = string.Empty; - } - } - } - - // This code was a constructor copied from the FrameworkName class, which is located in System.dll. - // Parses strings in the following format: ", Version=[v|V], Profile=" - // - The identifier and version is required, profile is optional - // - Only three components are allowed. - // - The version string must be in the System.Version format; an optional "v" or "V" prefix is allowed - private static bool TryParseFrameworkName(String frameworkName, out String identifier, out int version, out String profile) - { - // For parsing a target Framework moniker, from the FrameworkName class - const char c_componentSeparator = ','; - const char c_keyValueSeparator = '='; - const char c_versionValuePrefix = 'v'; - const String c_versionKey = "Version"; - const String c_profileKey = "Profile"; - - identifier = profile = string.Empty; - version = 0; - - if (frameworkName == null || frameworkName.Length == 0) - { - return false; - } - - String[] components = frameworkName.Split(c_componentSeparator); - version = 0; - - // Identifer and Version are required, Profile is optional. - if (components.Length < 2 || components.Length > 3) - { - return false; - } - - // - // 1) Parse the "Identifier", which must come first. Trim any whitespace - // - identifier = components[0].Trim(); - - if (identifier.Length == 0) - { - return false; - } - - bool versionFound = false; - profile = null; - - // - // The required "Version" and optional "Profile" component can be in any order - // - for (int i = 1; i < components.Length; i++) - { - // Get the key/value pair separated by '=' - string[] keyValuePair = components[i].Split(c_keyValueSeparator); - - if (keyValuePair.Length != 2) - { - return false; - } - - // Get the key and value, trimming any whitespace - string key = keyValuePair[0].Trim(); - string value = keyValuePair[1].Trim(); - - // - // 2) Parse the required "Version" key value - // - if (key.Equals(c_versionKey, StringComparison.OrdinalIgnoreCase)) - { - versionFound = true; - - // Allow the version to include a 'v' or 'V' prefix... - if (value.Length > 0 && (value[0] == c_versionValuePrefix || value[0] == 'V')) - { - value = value.Substring(1); - } - Version realVersion = new Version(value); - // The version class will represent some unset values as -1 internally (instead of 0). - version = realVersion.Major * 10000; - if (realVersion.Minor > 0) - version += realVersion.Minor * 100; - if (realVersion.Build > 0) - version += realVersion.Build; - } - // - // 3) Parse the optional "Profile" key value - // - else if (key.Equals(c_profileKey, StringComparison.OrdinalIgnoreCase)) - { - if (!String.IsNullOrEmpty(value)) - { - profile = value; - } - } - else - { - return false; - } - } - - if (!versionFound) - { - return false; - } - - return true; - } - - // This is a partial method. Platforms (such as Desktop) can provide an implementation of it that will read override value - // from whatever mechanism is available on that platform. If no implementation is provided, the compiler is going to remove the calls - // to it from the code - static partial void TryGetSwitchOverridePartial(string switchName, ref bool overrideFound, ref bool overrideValue); - - /// This is a partial method. This method is responsible for populating the default values based on a TFM. - /// It is partial because each library should define this method in their code to contain their defaults. - static partial void PopulateDefaultValuesPartial(string platformIdentifier, string profile, int version); - } -} - -#pragma warning restore 436 diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Misc/ExternDll.cs b/src/Microsoft.Data.SqlClient/netfx/src/Misc/ExternDll.cs index bbb6470a39..dbf8f4a9ee 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Misc/ExternDll.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Misc/ExternDll.cs @@ -6,80 +6,9 @@ namespace System { internal static class ExternDll { - -#if FEATURE_PAL && !SILVERLIGHT - -#if !PLATFORM_UNIX - internal const String DLLPREFIX = ""; - internal const String DLLSUFFIX = ".dll"; -#else // !PLATFORM_UNIX -#if __APPLE__ - internal const String DLLPREFIX = "lib"; - internal const String DLLSUFFIX = ".dylib"; -#elif _AIX - internal const String DLLPREFIX = "lib"; - internal const String DLLSUFFIX = ".a"; -#elif __hppa__ || IA64 - internal const String DLLPREFIX = "lib"; - internal const String DLLSUFFIX = ".sl"; -#else - internal const String DLLPREFIX = "lib"; - internal const String DLLSUFFIX = ".so"; -#endif -#endif // !PLATFORM_UNIX - - public const string Kernel32 = DLLPREFIX + "rotor_pal" + DLLSUFFIX; - public const string User32 = DLLPREFIX + "rotor_pal" + DLLSUFFIX; - public const string Mscoree = DLLPREFIX + "sscoree" + DLLSUFFIX; - -#elif FEATURE_PAL && SILVERLIGHT - - public const string Kernel32 = "coreclr"; - public const string User32 = "coreclr"; - - -#else - public const string Activeds = "activeds.dll"; public const string Advapi32 = "advapi32.dll"; - public const string Comctl32 = "comctl32.dll"; - public const string Comdlg32 = "comdlg32.dll"; - public const string Gdi32 = "gdi32.dll"; - public const string Gdiplus = "gdiplus.dll"; - public const string Hhctrl = "hhctrl.ocx"; - public const string Imm32 = "imm32.dll"; public const string Kernel32 = "kernel32.dll"; - public const string Loadperf = "Loadperf.dll"; - public const string Mscoree = "mscoree.dll"; - public const string Clr = "clr.dll"; - public const string Msi = "msi.dll"; - public const string Mqrt = "mqrt.dll"; - public const string Ntdll = "ntdll.dll"; public const string Ole32 = "ole32.dll"; - public const string Oleacc = "oleacc.dll"; public const string Oleaut32 = "oleaut32.dll"; - public const string Olepro32 = "olepro32.dll"; - public const string PerfCounter = "perfcounter.dll"; - public const string Powrprof = "Powrprof.dll"; - public const string Psapi = "psapi.dll"; - public const string Shell32 = "shell32.dll"; - public const string User32 = "user32.dll"; - public const string Uxtheme = "uxtheme.dll"; - public const string WinMM = "winmm.dll"; - public const string Winspool = "winspool.drv"; - public const string Wtsapi32 = "wtsapi32.dll"; - public const string Version = "version.dll"; - public const string Vsassert = "vsassert.dll"; - public const string Fxassert = "Fxassert.dll"; - public const string Shlwapi = "shlwapi.dll"; - public const string Crypt32 = "crypt32.dll"; - - // system.data specific - internal const string Odbc32 = "odbc32.dll"; - internal const string SNI = "System.Data.dll"; - - // system.data.oracleclient specific - internal const string OciDll = "oci.dll"; - internal const string OraMtsDll = "oramts.dll"; -#endif //!FEATURE_PAL } } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Misc/HResults.cs b/src/Microsoft.Data.SqlClient/netfx/src/Misc/HResults.cs deleted file mode 100644 index 86e26708e9..0000000000 --- a/src/Microsoft.Data.SqlClient/netfx/src/Misc/HResults.cs +++ /dev/null @@ -1,103 +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. - -/* -These HRESULTs are used for mapping managed exceptions to COM error codes -and vice versa through COM Interop. For background on COM error codes see -http://msdn.microsoft.com/library/default.asp?url=/library/en-us/com/error_9td2.asp. - -FACILITY_URT is defined as 0x13 (0x8013xxxx). The facility range is reserved -for the .NET Framework SDK teams. - -Within that range, the following subranges have been allocated for different -feature areas: - -0x10yy for Execution Engine -0x11yy for Metadata, TypeLib Export, and CLDB -0x12yy for MetaData Validator -0x13yy for Debugger and Profiler errors -0x14yy for Security -0x15yy for BCL -0x1600 - 0x161F for Reflection -0x1620 - 0x163F for System.IO -0x1640 - 0x165F for Security -0x1660 - 0x16FF for BCL -0x17yy for shim -0x18yy for IL Verifier -0x19yy for .NET Framework -0x1Ayy for .NET Framework -0x1Byy for MetaData Validator -0x30yy for VSA errors - -CLR HRESULTs are defined in corerror.h. If you make any modifications to -the range allocations described above, please make sure the corerror.h file -gets updated. -*/ - -namespace System -{ - internal static class HResults - { - - internal const int Configuration = unchecked((int)0x80131902); - - // Xml - internal const int Xml = unchecked((int)0x80131940); - internal const int XmlSchema = unchecked((int)0x80131941); - internal const int XmlXslt = unchecked((int)0x80131942); - internal const int XmlXPath = unchecked((int)0x80131943); - - // DataSet - internal const int Data = unchecked((int)0x80131920); - internal const int DataDeletedRowInaccessible = unchecked((int)0x80131921); - internal const int DataDuplicateName = unchecked((int)0x80131922); - internal const int DataInRowChangingEvent = unchecked((int)0x80131923); - internal const int DataInvalidConstraint = unchecked((int)0x80131924); - internal const int DataMissingPrimaryKey = unchecked((int)0x80131925); - internal const int DataNoNullAllowed = unchecked((int)0x80131926); - internal const int DataReadOnly = unchecked((int)0x80131927); - internal const int DataRowNotInTable = unchecked((int)0x80131928); - internal const int DataVersionNotFound = unchecked((int)0x80131929); - internal const int DataConstraint = unchecked((int)0x8013192A); - internal const int StrongTyping = unchecked((int)0x8013192B); - - // Managed Providers - internal const int SqlType = unchecked((int)0x80131930); - internal const int SqlNullValue = unchecked((int)0x80131931); - internal const int SqlTruncate = unchecked((int)0x80131932); - internal const int AdapterMapping = unchecked((int)0x80131933); - internal const int DataAdapter = unchecked((int)0x80131934); - internal const int DBConcurrency = unchecked((int)0x80131935); - internal const int OperationAborted = unchecked((int)0x80131936); - internal const int InvalidUdt = unchecked((int)0x80131937); - internal const int Metadata = unchecked((int)0x80131939); - internal const int InvalidQuery = unchecked((int)0x8013193A); - internal const int CommandCompilation = unchecked((int)0x8013193B); - internal const int CommandExecution = unchecked((int)0x8013193C); - - - internal const int SqlException = unchecked((int)0x80131904); // Microsoft.Data.SqlClient.SqlClientException - internal const int OdbcException = unchecked((int)0x80131937); // System.Data.Odbc.OdbcException - internal const int OracleException = unchecked((int)0x80131938); // System.Data.OracleClient.OracleException - internal const int ConnectionPlanException = unchecked((int)0x8013193d); // Microsoft.Data.SqlClient.ConnectionPlanException - - // Configuration encryption - internal const int NteBadKeySet = unchecked((int)0x80090016); - - // Win32 - internal const int Win32AccessDenied = unchecked((int)0x80070005); - internal const int Win32InvalidHandle = unchecked((int)0x80070006); - - -#if !FEATURE_PAL - internal const int License = unchecked((int)0x80131901); - internal const int InternalBufferOverflow = unchecked((int)0x80131905); - internal const int ServiceControllerTimeout = unchecked((int)0x80131906); - internal const int Install = unchecked((int)0x80131907); - - // Win32 - internal const int EFail = unchecked((int)0x80004005); -#endif - } -} diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Misc/LocalAppContext.cs b/src/Microsoft.Data.SqlClient/netfx/src/Misc/LocalAppContext.cs deleted file mode 100644 index c07ba8f943..0000000000 --- a/src/Microsoft.Data.SqlClient/netfx/src/Misc/LocalAppContext.cs +++ /dev/null @@ -1,136 +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. - -// There are cases where we have multiple assemblies that are going to import this file and -// if they are going to also have InternalsVisibleTo between them, there will be a compiler warning -// that the type is found both in the source and in a referenced assembly. The compiler will prefer -// the version of the type defined in the source -// -// In order to disable the warning for this type we are disabling this warning for this entire file. -#pragma warning disable 436 - -// NOTE: This file should not be included in mscorlib. This should only be included in FX libraries that need to provide switches -using System.Collections.Generic; -using System.Reflection; -using System.Runtime.CompilerServices; - -namespace System -{ - internal static partial class LocalAppContext - { - private delegate bool TryGetSwitchDelegate(string switchName, out bool value); - - private static TryGetSwitchDelegate TryGetSwitchFromCentralAppContext; - private static bool s_canForwardCalls; - - private static Dictionary s_switchMap = new Dictionary(); - private static readonly object s_syncLock = new object(); - - private static bool DisableCaching { get; set; } - - static LocalAppContext() - { - // Try to setup the callback into the central AppContext - s_canForwardCalls = SetupDelegate(); - - // Populate the default values of the local app context - AppContextDefaultValues.PopulateDefaultValues(); - - // Cache the value of the switch that help with testing - DisableCaching = IsSwitchEnabled(@"TestSwitch.LocalAppContext.DisableCaching"); - } - - public static bool IsSwitchEnabled(string switchName) - { - if (s_canForwardCalls) - { - bool isEnabledCentrally; - if (TryGetSwitchFromCentralAppContext(switchName, out isEnabledCentrally)) - { - // we found the switch, so return whatever value it has - return isEnabledCentrally; - } - // if we could not get the value from the central authority, try the local storage. - } - - return IsSwitchEnabledLocal(switchName); - } - - private static bool IsSwitchEnabledLocal(string switchName) - { - // read the value from the set of local defaults - bool isEnabled, isPresent; - lock (s_switchMap) - { - isPresent = s_switchMap.TryGetValue(switchName, out isEnabled); - } - - // If the value is in the set of local switches, reutrn the value - if (isPresent) - { - return isEnabled; - } - - // if we could not find the switch name, we should return 'false' - // This will preserve the concept of switches been 'off' unless explicitly set to 'on' - return false; - } - - private static bool SetupDelegate() - { - Type appContextType = typeof(object).Assembly.GetType("System.AppContext"); - if (appContextType == null) - return false; - - MethodInfo method = appContextType.GetMethod( - "TryGetSwitch", // the method name - BindingFlags.Static | BindingFlags.Public, // binding flags - null, // use the default binder - new Type[] { typeof(string), typeof(bool).MakeByRefType() }, - null); // parameterModifiers - this is ignored by the default binder - if (method == null) - return false; - - // Create delegate if we found the method. - TryGetSwitchFromCentralAppContext = (TryGetSwitchDelegate)Delegate.CreateDelegate(typeof(TryGetSwitchDelegate), method); - - return true; - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - internal static bool GetCachedSwitchValue(string switchName, ref int switchValue) - { - if (switchValue < 0) - return false; - if (switchValue > 0) - return true; - - return GetCachedSwitchValueInternal(switchName, ref switchValue); - } - - private static bool GetCachedSwitchValueInternal(string switchName, ref int switchValue) - { - if (LocalAppContext.DisableCaching) - { - return LocalAppContext.IsSwitchEnabled(switchName); - } - - bool isEnabled = LocalAppContext.IsSwitchEnabled(switchName); - switchValue = isEnabled ? 1 /*true*/ : -1 /*false*/; - return isEnabled; - } - - /// - /// This method is going to be called from the AppContextDefaultValues class when setting up the - /// default values for the switches. !!!! This method is called during the static constructor so it does not - /// take a lock !!!! If you are planning to use this outside of that, please ensure proper locking. - /// - internal static void DefineSwitchDefault(string switchName, bool initialValue) - { - s_switchMap[switchName] = initialValue; - } - } -} - -#pragma warning restore 436 diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Misc/PrivilegedConfigurationManager.cs b/src/Microsoft.Data.SqlClient/netfx/src/Misc/PrivilegedConfigurationManager.cs deleted file mode 100644 index a4ec059ac4..0000000000 --- a/src/Microsoft.Data.SqlClient/netfx/src/Misc/PrivilegedConfigurationManager.cs +++ /dev/null @@ -1,26 +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. - -namespace System.Configuration -{ - using System.Security.Permissions; - - [ConfigurationPermission(SecurityAction.Assert, Unrestricted = true)] - internal static class PrivilegedConfigurationManager - { - internal static ConnectionStringSettingsCollection ConnectionStrings - { - [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - get - { - return ConfigurationManager.ConnectionStrings; - } - } - - internal static object GetSection(string sectionName) - { - return ConfigurationManager.GetSection(sectionName); - } - } -} diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs new file mode 100644 index 0000000000..4db177d0ac --- /dev/null +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/LocalAppContextSwitches.cs @@ -0,0 +1,23 @@ +// 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.Runtime.CompilerServices; + +namespace Microsoft.Data.SqlClient +{ + internal static partial class LocalAppContextSwitches + { + internal const string MakeReadAsyncBlockingString = @"Switch.Microsoft.Data.SqlClient.MakeReadAsyncBlocking"; + private static bool _makeReadAsyncBlocking; + public static bool MakeReadAsyncBlocking + { + [MethodImpl(MethodImplOptions.AggressiveInlining)] + get + { + return AppContext.TryGetSwitch(MakeReadAsyncBlockingString, out _makeReadAsyncBlocking) ? _makeReadAsyncBlocking : true; + } + } + } +}