question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Presence of various section in app.config breaks initialiser

See original GitHub issue

The presence of a configSections in an app.config breaks the connection initialiser. To reproduce just create the most basic app possible (server name etc. is irrelevant):

using Microsoft.Data.SqlClient;

namespace TestSQL
{
    class Program
    {
        static void Main(string[] args)
        {
            var connection = new SqlConnection("data source=.;initial catalog=blah;Trusted_Connection=Yes;persist security info=False");
            connection.Open();
        }
    }
}

Adding an app.config with various combinations of sections such as

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <appSettings>
        <add key="ConfigFolder" value="./config" />
    </appSettings>
    <configSections>
        <clear />
    </configSections>
</configuration>

causes the exception, as does adding a <system.diagnostics> section.

Unhandled exception. System.TypeInitializationException: The type initializer for 'Microsoft.Data.SqlClient.SqlAuthenticationProviderManager' threw an exception.
 ---> System.InvalidOperationException: Failed to read the config section for authentication providers.
 ---> System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize
 ---> System.Configuration.ConfigurationErrorsException: Only one <configSections> element allowed per config file and if present must be the first child of the root <configuration> element. (C:\Users\Jason\RiderProjects\TestSQL\TestSQL\bin\Debug\netcoreapp3.
0\TestSQL.dll.config line 6)
   at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
   at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
   at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
   at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
   --- End of inner exception stack trace ---
   at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
   at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
   at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
   at System.Configuration.ConfigurationManager.GetSection(String sectionName)
   at Microsoft.Data.SqlClient.SqlAuthenticationProviderManager..cctor()
   --- End of inner exception stack trace ---
   at Microsoft.Data.SqlClient.SqlAuthenticationProviderManager..cctor()
   --- End of inner exception stack trace ---
   at Microsoft.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserIn
stance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken, DbConnectionPool pool, SqlAuthenticationProviderManager sqlAuthProviderManager)
   at Microsoft.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   at Microsoft.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
   at Microsoft.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at Microsoft.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at Microsoft.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at Microsoft.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at Microsoft.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at Microsoft.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at Microsoft.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   at Microsoft.Data.SqlClient.SqlConnection.Open()
   at TestSQL.Program.Main(String[] args) in C:\Users\Jason\RiderProjects\TestSQL\TestSQL\Program.cs:line 10

This is on .Net Core 3.0 or 3.1, Microsoft.Data.SqlClient, Version=1.12.20106.1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jsobellcommented, May 25, 2020

Awesome speedy work @cheenamalhotra We’re still on 1.1 so can’t test, but did a code review and looks perfect, thanks.

0reactions
cheenamalhotracommented, May 22, 2020

@jsobell

Please give PR #573 a try and let us know!

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - app.config - configuration system failed to initialize with ...
A configuration section can only appear 1 time within a configuration file. The full initialization exception shows: System.Configuration.
Read more >
Configuring Rails Applications
Configuring Rails ApplicationsThis guide covers the configuration and initialization features available to Rails applications.After reading this guide, ...
Read more >
System.diagnostics entry in app.config - .NET
Learn about the .NET 7 breaking change in configuration where the `` entry is no longer allowed in an app.config file.
Read more >
“How-to” Guides
This section includes topics relating directly to Spring Boot ... per application, by setting the context.initializer.classes or ...
Read more >
Home (Monitor) Presence App V2 - Share your Projects!
I love that I am able to configure (virtually) everything from apps.yaml. The readme doesn't have the usual flow of install steps then...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found