-
Notifications
You must be signed in to change notification settings - Fork 286
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
app.config breaks the library #287
Comments
@yorek From the error you're getting (
I was able to initialize SqlConnection just fine. |
@yukiwongky What is the behavior on .Net framework v4.8 ? I know that SqlConnection class tries to load some values from the App.Config to initialize providers for always encrypted and for auth providers for AAD. It might be worth checking out the behavior of DbProviderFactory (an API which I picked up, which depends on App.config) to see what the behavior is, in case of a malformed app.config https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/obtaining-a-dbproviderfactory If the API fails to load the db provider factory silently, then it may perhaps be good to make SqlConnection static constructor to fail silently instead of preventing initialization. |
@yukiwongky right but if the file is there and is empty, or contains json, you'll get the error. If "app.config" file must be an XML, it's better to call it out clearly in the doc, as with System.Data.SqlClient, there are no problem instead. |
@saurabh500 I see the exception comes from SqlConnection.cs#L40 when the configuration file can not be loaded. And I also found in DbProviderFactories.cs that the exception is just ignored. We can do the same in the MDS driver as well, instead of throwing an exception, make |
Yeah I agree with the approach |
@yukiwongky great! :) |
Hi @yorek, we have the fix in v1.1.0-preview2. Can you give it a try? |
Hi. Just tried it. Now I receive just this error:
I'm using this simple code to test the library:
and this is the .csprj file:
It works nice until you create an app.config file in the same folder. The app.config file is set to be
|
Don't throw exception on invalid app.config files (dotnet#287)
Addressed in #319 |
I don't think this is fixed in v1.1.0 I'm still getting the following exception when my config looks something like: <?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="Logging.Level" value="Debug" />
</appSettings>
<system.diagnostics>
<sources>
<source name="Halibut">
<listeners>
<add name="nlog" />
</listeners>
</source>
</sources>
<switches>
<add name="Halibut" value="Verbose" />
</switches>
<sharedListeners>
<add name="nlog" type="NLog.NLogTraceListener, NLog" />
</sharedListeners>
<trace autoflush="true" />
</system.diagnostics>
<runtime>
<gcServer enabled="true" />
</runtime>
</configuration> Exception stacktrace:
|
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"
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)
The text was updated successfully, but these errors were encountered: