0

I have a .net class library 2.0 with an app.config with a connectionString section.

I have 01 Method that this class library exposes " string GetConnectionString(string name)

However even though the app.config in this class library has 3 connstrings it does not read this config.exe.How can I make it read the app.config that resides withing this dll?

Again, Usually you will have a web or windows app with a config and it will all work. Mine is a special case I need to read the connectionstring within this class library.

How can I do it?

thanks a lot

1 Answer 1

3

Class libraries don't have app.configs. You might have a file in your class library project named app.config but it's not considered the application's configuration file. The only file that matters is the app.config of the .exe which uses your class library.

One possible solution is to move the definitions of the connection strings from your app.config file from your class library's project into your .exe's project.

Another option is to interact with the app.config as a standard xml document to retrieve the values you're looking for.

Sign up to request clarification or add additional context in comments.

6 Comments

And of course if its not a *.exe.config file because its a web application, then the connection string will have to be in the web.config file instead.
I cannot move the app.config into my exe.that would solve the problem immediately. What About creating a customSection.Is this the only way?
Creating a customSection won't help you because those work with the app.config. If you could put this data in the app.config then you wouldn't have a problem to begin with. It's not really a problem. Just release yourself from the idea that you must use the System.Configuration namespace to access the data in that file and achieve it through other technologies.
Ok.I think I should stop treating it as app.config but as a Normal xml file. Is there a way to get the path for the assembly in which the App.Config resides.And it will work. Below path is wrong. string path = Path.Combine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().CodeBase),"App.config"); ExeConfigurationFileMap configFileMap =new ExeConfigurationFileMap(); configFileMap.ExeConfigFilename = path; var config = ConfigurationManager.OpenMappedExeConfiguration(configFileMap,ConfigurationUserLevel.None);
it's a classic asp application calling a .net dll with the aim of getting connection string from a config file that resides in the .net dll.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.