Skip to content

Xamarin.Android - SqlClient connection broken since 5.1.1 #2251

@farlop

Description

@farlop

Describe the bug

Until version 5.1.0, a Xamarin Forms application running in Android could connect to an SQL Server database directly.

When tried to upgrade to latest, I've found that some change in 5.1.1 is causing to fail. Reverting to 5.1.0 solves the problem.

Exceptions info:

(System.ArgumentNullException) Value cannot be null.
Parameter name: path1  at System.IO.Path.Combine (System.String path1, System.String path2) [0x00003] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.IO/Path.cs:102 
  at System.Configuration.ClientConfigurationHost.get_MachineConfigFilePath () [0x00014] in <860085a6305a40768f26304153de5416>:0 
  at System.Configuration.ClientConfigurationHost.GetStreamName (System.String configPath) [0x00051] in <860085a6305a40768f26304153de5416>:0 
  at System.Configuration.Internal.DelegatingConfigHost.GetStreamName (System.String configPath) [0x00006] in <860085a6305a40768f26304153de5416>:0 
  at System.Configuration.ImplicitMachineConfigHost.GetStreamName (System.String configPath) [0x00000] in <860085a6305a40768f26304153de5416>:0 
  at System.Configuration.BaseConfigurationRecord.InitConfigFromFile () [0x00049] in <860085a6305a40768f26304153de5416>:0 
=======================================================(inner most exception)===
 (1) System.ArgumentNullException
================================================================================
Message:
"Value cannot be null.
Parameter name: path1"
Properties:
  String.ParamName = "path1"
Stack Trace:
  at System.IO.Path.Combine (System.String path1, System.String path2) [0x00003] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.IO/Path.cs:102 
  at System.Configuration.ClientConfigurationHost.get_MachineConfigFilePath () [0x00014] in <860085a6305a40768f26304153de5416>:0 
  at System.Configuration.ClientConfigurationHost.GetStreamName (System.String configPath) [0x00051] in <860085a6305a40768f26304153de5416>:0 
  at System.Configuration.Internal.DelegatingConfigHost.GetStreamName (System.String configPath) [0x00006] in <860085a6305a40768f26304153de5416>:0 
  at System.Configuration.ImplicitMachineConfigHost.GetStreamName (System.String configPath) [0x00000] in <860085a6305a40768f26304153de5416>:0 
  at System.Configuration.BaseConfigurationRecord.InitConfigFromFile () [0x00049] in <860085a6305a40768f26304153de5416>:0 
================================================================================
================================================================================
 (2) System.Configuration.ConfigurationErrorsException
================================================================================
Message:
"An error occurred loading a configuration file: Value cannot be null.
Parameter name: path1"
Properties:
  String.Filename = ""
  Int32.Line = "0"
  ICollection.Errors = {
    "System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Value cannot be null.
Parameter name: path1 ---> System.ArgumentNullException: Value cannot be null.
Parameter name: path1
  at System.IO.Path.Combine (System.String path1, System.String path2) [0x00003] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.IO/Path.cs:102 
  at System.Configuration.ClientConfigurationHost.get_MachineConfigFilePath () [0x00014] in <860085a6305a40768f26304153de5416>:0 
  at System.Configuration.ClientConfigurationHost.GetStreamName (System.String configPath) [0x00051] in <860085a6305a40768f26304153de5416>:0 
  at System.Configuration.Internal.DelegatingConfigHost.GetStreamName (System.String configPath) [0x00006] in <860085a6305a40768f26304153de5416>:0 
  at System.Configuration.ImplicitMachineConfigHost.GetStreamName (System.String configPath) [0x00000] in <860085a6305a40768f26304153de5416>:0 
  at System.Configuration.BaseConfigurationRecord.InitConfigFromFile () [0x00049] in <860085a6305a40768f26304153de5416>:0 
   --- End of inner exception stack trace ---",
  }
  String.BareMessage = "An error occurred loading a configuration file: Value cannot be null.
Parameter name: path1"
Stack Trace:
  at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors (System.Boolean ignoreLocal) [0x0001d] in <860085a6305a40768f26304153de5416>:0 
  at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors (System.Configuration.ConfigurationSchemaErrors schemaErrors) [0x00011] in <860085a6305a40768f26304153de5416>:0 
  at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors () [0x00000] in <860085a6305a40768f26304153de5416>:0 
  at System.Configuration.ClientConfigurationSystem.EnsureInit (System.String configKey) [0x00060] in <860085a6305a40768f26304153de5416>:0 
================================================================================
================================================================================
 (3) System.Configuration.ConfigurationErrorsException
================================================================================
Message:
"Configuration system failed to initialize"
Properties:
  String.Filename = ""
  Int32.Line = "0"
  ICollection.Errors = {
    "System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.Configuration.ConfigurationErrorsException: An error occurred loading a configuration file: Value cannot be null.
Parameter name: path1 ---> System.ArgumentNullException: Value cannot be null.
Parameter name: path1
  at System.IO.Path.Combine (System.String path1, System.String path2) [0x00003] in /Users/builder/jenkins/workspace/archive-mono/2020-02/android/release/mcs/class/corlib/System.IO/Path.cs:102 
  at System.Configuration.ClientConfigurationHost.get_MachineConfigFilePath () [0x00014] in <860085a6305a40768f26304153de5416>:0 
  at System.Configuration.ClientConfigurationHost.GetStreamName (System.String configPath) [0x00051] in <860085a6305a40768f26304153de5416>:0 
  at System.Configuration.Internal.DelegatingConfigHost.GetStreamName (System.String configPath) [0x00006] in <860085a6305a40768f26304153de5416>:0 
  at System.Configuration.ImplicitMachineConfigHost.GetStreamName (System.String configPath) [0x00000] in <860085a6305a40768f26304153de5416>:0 
  at System.Configuration.BaseConfigurationRecord.InitConfigFromFile () [0x00049] in <860085a6305a40768f26304153de5416>:0 
   --- End of inner exception stack trace ---
  at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors (System.Boolean ignoreLocal) [0x0001d] in <860085a6305a40768f26304153de5416>:0 
  at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors (System.Configuration.ConfigurationSchemaErrors schemaErrors) [0x00011] in <860085a6305a40768f26304153de5416>:0 
  at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors () [0x00000] in <860085a6305a40768f26304153de5416>:0 
  at System.Configuration.ClientConfigurationSystem.EnsureInit (System.String configKey) [0x00060] in <860085a6305a40768f26304153de5416>:0 
   --- End of inner exception stack trace ---",
  }
  String.BareMessage = "Configuration system failed to initialize"
Stack Trace:
  at System.Configuration.ConfigurationManager.PrepareConfigSystem () [0x0001a] in <860085a6305a40768f26304153de5416>:0 
  at System.Configuration.ConfigurationManager.GetSection (System.String sectionName) [0x0000a] in <860085a6305a40768f26304153de5416>:0 
  at System.Runtime.Caching.MemoryCacheStatistics.InitializeConfiguration (System.Collections.Specialized.NameValueCollection config) [0x00016] in <a8fc702de12a46699fa97a1cc0178b91>:0 
  at System.Runtime.Caching.MemoryCacheStatistics..ctor (System.Runtime.Caching.MemoryCache memoryCache, System.Collections.Specialized.NameValueCollection config) [0x0002a] in <a8fc702de12a46699fa97a1cc0178b91>:0 
  at System.Runtime.Caching.MemoryCache.InitDisposableMembers (System.Collections.Specialized.NameValueCollection config) [0x0004e] in <a8fc702de12a46699fa97a1cc0178b91>:0 
  at System.Runtime.Caching.MemoryCache.Init (System.Collections.Specialized.NameValueCollection config) [0x00031] in <a8fc702de12a46699fa97a1cc0178b91>:0 
  at System.Runtime.Caching.MemoryCache..ctor (System.String name, System.Collections.Specialized.NameValueCollection config) [0x00058] in <a8fc702de12a46699fa97a1cc0178b91>:0 
  at Microsoft.Data.SqlClient.ActiveDirectoryAuthenticationProvider..cctor () [0x0000a] in <11becafcfd0b40b6ac61fd8694820c39>:0 
================================================================================
================================================================================
 (4) System.TypeInitializationException
================================================================================
Message:
"The type initializer for 'Microsoft.Data.SqlClient.ActiveDirectoryAuthenticationProvider' threw an exception."
Properties:
  String.TypeName = "Microsoft.Data.SqlClient.ActiveDirectoryAuthenticationProvider"
Stack Trace:
  at Microsoft.Data.SqlClient.SqlAuthenticationProviderManager.SetDefaultAuthProviders (Microsoft.Data.SqlClient.SqlAuthenticationProviderManager instance) [0x00003] in <11becafcfd0b40b6ac61fd8694820c39>:0 
  at Microsoft.Data.SqlClient.SqlAuthenticationProviderManager..cctor () [0x0000a] in <11becafcfd0b40b6ac61fd8694820c39>:0 
================================================================================
================================================================================
 (5) System.TypeInitializationException
================================================================================
Message:
"The type initializer for 'Microsoft.Data.SqlClient.SqlAuthenticationProviderManager' threw an exception."
Properties:
  String.TypeName = "Microsoft.Data.SqlClient.SqlAuthenticationProviderManager"
Stack Trace:
  at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection (System.Data.Common.DbConnection owningObject, System.UInt32 waitForMultipleObjectsTimeout, System.Boolean allowCreate, System.Boolean onlyOneCheckConnection, Microsoft.Data.Common.DbConnectionOptions userOptions, Microsoft.Data.ProviderBase.DbConnectionInternal& connection) [0x000c4] in <11becafcfd0b40b6ac61fd8694820c39>:0 
  at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection (System.Data.Common.DbConnection owningObject, System.Threading.Tasks.TaskCompletionSource`1[TResult] retry, Microsoft.Data.Common.DbConnectionOptions userOptions, Microsoft.Data.ProviderBase.DbConnectionInternal& connection) [0x0003b] in <11becafcfd0b40b6ac61fd8694820c39>:0 
  at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection (System.Data.Common.DbConnection owningConnection, System.Threading.Tasks.TaskCompletionSource`1[TResult] retry, Microsoft.Data.Common.DbConnectionOptions userOptions, Microsoft.Data.ProviderBase.DbConnectionInternal oldConnection, Microsoft.Data.ProviderBase.DbConnectionInternal& connection) [0x0014d] in <11becafcfd0b40b6ac61fd8694820c39>:0 
  at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal (System.Data.Common.DbConnection outerConnection, Microsoft.Data.ProviderBase.DbConnectionFactory connectionFactory, System.Threading.Tasks.TaskCompletionSource`1[TResult] retry, Microsoft.Data.Common.DbConnectionOptions userOptions) [0x00036] in <11becafcfd0b40b6ac61fd8694820c39>:0 
  at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection (System.Data.Common.DbConnection outerConnection, Microsoft.Data.ProviderBase.DbConnectionFactory connectionFactory, System.Threading.Tasks.TaskCompletionSource`1[TResult] retry, Microsoft.Data.Common.DbConnectionOptions userOptions) [0x00000] in <11becafcfd0b40b6ac61fd8694820c39>:0 
  at Microsoft.Data.SqlClient.SqlConnection.TryOpen (System.Threading.Tasks.TaskCompletionSource`1[TResult] retry, Microsoft.Data.SqlClient.SqlConnectionOverrides overrides) [0x000f0] in <11becafcfd0b40b6ac61fd8694820c39>:0 
  at Microsoft.Data.SqlClient.SqlConnection.Open (Microsoft.Data.SqlClient.SqlConnectionOverrides overrides) [0x00082] in <11becafcfd0b40b6ac61fd8694820c39>:0 
  at Microsoft.Data.SqlClient.SqlConnection.Open () [0x00000] in <11becafcfd0b40b6ac61fd8694820c39>:0 
  at Honeywell.GWS.Connector.Library.Workflows.Checklist.SqlServer.Behavior.GetOperator (System.String operator) [0x0003d] in C:\DesarrolloNET\GWS-Workflows.Checklist\src\GWS-Workflows.Checklist.SqlServer\Behavior.cs:96 
  at Honeywell.GWS.Connector.Library.Workflows.Checklist.Workflow.ConnectAsync (Honeywell.GWS.Connector.SDK.Interfaces.IDevice device) [0x00000] in C:\DesarrolloNET\GWS-Workflows.Checklist\src\GWS-Workflows.Checklist\Workflow.cs:47 
  at VIO.VIOPluginDataTransport.SignOnAsync (System.String operatorId) [0x00058] in C:\DevKit\GWS App\src\VIOModule\Services\DataService\VIOPluginDataTransport.cs:294 
================================================================================

To reproduce

Include a complete code listing (or project/solution) that we can run to reproduce the issue.

Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.

try
{
    using var cn = new SqlConnection("Server=172.20.18.143, 1433;Database=GWS-Workflows-Checklist;User Id=gws;Password=***;TrustServerCertificate=True;");

    cn.Open();
}
catch (Exception ex)
{
    // Exception is always raised
}

Expected behavior

Connection should be made and exception not be raised

Further technical details

Microsoft.Data.SqlClient version: 5.1.1
.NET target: Xamarin Forms
SQL Server version: SQL Server 2017
Operating system: Android

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Closed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions