Skip to content

app.config breaks the library #287

@yorek

Description

@yorek

Describe the bug

If you have an app.config file in your solution it will cause the error "The type initializer for 'Microsoft.Data.SqlClient.SqlConnection' threw an exception"

An exception of type 'System.TypeInitializationException' occurred in Microsoft.Data.SqlClient.dll but was not handled in user code: 'The type initializer for 'Microsoft.Data.SqlClient.SqlConnection' threw an exception.'
 Inner exceptions found, see $exception in variables window for more details.
 Innermost exception 	 System.Xml.XmlException : Data at the root level is invalid. Line 1, position 1.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
   at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlTextReaderImpl.Read()
   at System.Xml.XmlTextReader.Read()
   at System.Configuration.XmlUtil..ctor(Stream stream, String name, Boolean readToFirstElement, ConfigurationSchemaErrors schemaErrors)
   at System.Configuration.BaseConfigurationRecord.InitConfigFromFile()

To reproduce

Just create a sample console app that uses Microsoft.Data.SqlClient and add an app.config file. It could be even an empty file.

Expected behavior

Do not crash :)

Further technical details

Microsoft.Data.SqlClient version: 1.0.19269.1
.NET target: (e.g. Framework Core 2.1)
Operating system: (e.g. Windows 10)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions