Skip to content

Commit

Permalink
Fix | MARS header contains errors on .NET Framework 4.8 (#910)
Browse files Browse the repository at this point in the history
* MARS header errors fix
  • Loading branch information
David Engel authored Feb 26, 2021
1 parent d1e3a69 commit 0467506
Show file tree
Hide file tree
Showing 15 changed files with 49 additions and 606 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@
<Compile Include="..\..\src\Microsoft\Data\SqlClient\AzureManagedIdentityAuthenticationProvider.cs">
<Link>Microsoft\Data\SqlClient\AzureManagedIdentityAuthenticationProvider.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\LocalAppContextSwitches.cs">
<Link>Microsoft\Data\SqlClient\LocalAppContextSwitches.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\Server\ExtendedClrTypeCode.cs">
<Link>Microsoft\Data\SqlClient\Server\ExtendedClrTypeCode.cs</Link>
</Compile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@
</ItemGroup>
<!-- Contains common items shared between NetFx and NetCore -->
<ItemGroup>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\LocalAppContextSwitches.cs">
<Link>Microsoft\Data\SqlClient\LocalAppContextSwitches.cs</Link>
</Compile>
<Compile Include="..\..\src\Microsoft\Data\SqlClient\SqlClientEventSource.cs">
<Link>Microsoft\Data\SqlClient\SqlClientEventSource.cs</Link>
</Compile>
Expand Down Expand Up @@ -337,11 +340,10 @@
<Compile Include="Microsoft\Data\Interop\SNINativeManagedWrapperX86.cs" />
<Compile Include="Microsoft\Data\Interop\SNINativeMethodWrapper.cs" />
<Compile Include="Microsoft\Data\SqlClient\AlwaysEncryptedEnclaveProviderUtils.cs" />
<Compile Include="Microsoft\Data\SqlClient\AppContextDefaultValues.Defaults.cs" />
<Compile Include="Microsoft\Data\SqlClient\assemblycache.cs" />
<Compile Include="Microsoft\Data\SqlClient\AzureAttestationBasedEnclaveProvider.cs" />
<Compile Include="Microsoft\Data\SqlClient\EnclaveDelegate.cs" />
<Compile Include="Microsoft\Data\SqlClient\LocalAppContextSwitches.cs" />
<Compile Include="Microsoft\Data\SqlClient\LocalAppContextSwitches.netfx.cs" />
<Compile Include="Microsoft\Data\SqlClient\LocalDBAPI.cs" />
<Compile Include="Microsoft\Data\SqlClient\LocalDBConfig.cs" />
<Compile Include="Microsoft\Data\SqlClient\AssemblyRef.cs" />
Expand Down Expand Up @@ -426,10 +428,6 @@
<Compile Include="Microsoft\Data\Common\GreenMethods.cs" />
<Compile Include="Microsoft\Data\Common\SQLResource.cs" />
<Compile Include="Misc\ExternDll.cs" />
<Compile Include="Misc\HResults.cs" />
<Compile Include="Misc\LocalAppContext.cs" />
<Compile Include="Misc\AppContextDefaultValues.cs" />
<Compile Include="Misc\PrivilegedConfigurationManager.cs" />
<Compile Include="Common\src\Microsoft\Data\Common\NameValuePermission.cs" />
<Compile Include="Microsoft\Data\Common\AdapterSwitches.cs" />
<Compile Include="Microsoft\Data\Common\AdapterUtil.cs" />
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ internal static void CreateLocalDBInstance(string instance)
if (s_configurableInstances == null)
{
Dictionary<string, InstanceInfo> tempConfigurableInstances = new Dictionary<string, InstanceInfo>(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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,44 +206,18 @@ override protected DbConnectionPoolGroupOptions CreateConnectionPoolGroupOptions
return poolingOptions;
}

// SxS (VSDD 545786): metadata files are opened from <.NetRuntimeFolder>\CONFIG\<metadatafilename.xml>
// 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ 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)]
private Guid _clientConnectionId = Guid.Empty;

private SqlException(string message, SqlErrorCollection errorCollection, Exception innerException, Guid conId) : base(message, innerException)
{
HResult = HResults.SqlException;
HResult = SqlExceptionHResult;
_errors = errorCollection;
_clientConnectionId = conId;
}
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading

0 comments on commit 0467506

Please sign in to comment.