Presence of various section in app.config breaks initialiser
See original GitHub issueThe 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:
- Created 3 years ago
- Reactions:1
- Comments:7 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Awesome speedy work @cheenamalhotra We’re still on 1.1 so can’t test, but did a code review and looks perfect, thanks.
@jsobell
Please give PR #573 a try and let us know!