I'm trying to run some code in the VS2015 c# interactive window which uses a connection string stored in the app.config file of a dll which I'm referencing using the #r
function.
If I look in the ConfigurationManager
there is a connection string in it but it's a different one which it must be referencing from another config file.
If what you want is to explicitly load the configuration for a specific assembly and explicitly access it, you can use the OpenExeConfiguration method of the ConfigurationManager class.
Take a test.dll assembly with this test.dll.config configuration file:
<configuration>
<connectionStrings>
<add
name="MyConnectionString"
connectionString="my connection string"
providerName="System.Data.SqlClient"
/>
</connectionStrings>
</configuration>
You cam load the configuration file like this:
> #r "c:\temp\test.dll"
> #r "System.Configuration"
> using System.Configuration;
> ConfigurationManager.OpenExeConfiguration(@"c:\temp\test.dll").ConnectionStrings.ConnectionStrings["MyConnectionString"].ConnectionString
"my connection string"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With