Access to configuration file from C # interactive window

I am trying to run some code in a VS2015 C # interactive window that uses the connection string stored in the app.config dll file that I refer to using the #r function.

If I look in the ConfigurationManager , it has a connection string in it, and another one that it should reference from another configuration file.

+7
c # visual-studio-2015 roslyn c # -interactive
source share
1 answer

If you want to explicitly load the configuration for a specific assembly and explicitly access it, you can use the OpenExeConfiguration Method of the ConfigurationManager class .

Take the 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 will purchase a configuration file as follows:

 > #r "c:\temp\test.dll" > #r "System.Configuration" > using System.Configuration; > ConfigurationManager.OpenExeConfiguration(@"c:\temp\test.dll").ConnectionStrings.ConnectionStrings["MyConnectionString"].ConnectionString "my connection string" 
0
source share

All Articles