Microsoft Developer Network >
Página principal de foros
>
Visual C# General
>
Using embedded App.Config
Using embedded App.Config
- What are the consequences of making an App.Config file an embedded resource?
When accessing the config file will it check both the calling application's config file as well as its own embedded app.config file or how does it work?
Todas las respuestas
You could surely embed an app.config in your executable and then use reflection etc. to use the settings in a read-only manner, but why would you want to do that when you can easily read the settings directly through the Settings class (even without deploying your app.config)?
If you need to use specific configuration data with your libraries, use ConfigurationManager.OpenExeConfiguration().
- I am referencing a web service which requires certain settings in the App.Config file, but I don't want the calling application to have this information in its app.config file, I want my dll to have it and access it. Do you know what I mean?
- If you want a specific app.config for a dll, make one.
Name it according to the dll, and not according to the main executable:
SomeAssembly.dll.config
This won't be accessible to the calling application.
Coding Light - Illuminated Ideas and Algorithms in Software
Coding Light Wiki • LinkedIn • ForumsBrowser- Marcado como respuestaHarry ZhuMSFT, Moderadorjueves, 12 de noviembre de 2009 6:31
- Votado como útilTheLearner jueves, 12 de noviembre de 2009 9:06
- Desmarcado como respuestaTheLearner jueves, 12 de noviembre de 2009 9:06
- Propuesto como respuestaHarry ZhuMSFT, Moderadormiércoles, 11 de noviembre de 2009 2:01
- Use ConfigurationManager.OpenExeConfiguration() from within your library to open the configuration file as needed. If your concern is about confidentiality, why not encrypt/obfuscate the section containing the sensitive data?
Maybe I don't get it right, but after all, what's the use of a read-only configuration that never changes and is not accessible from outside the executable (library)? You could as well create an internal custom class exposing the properties you need. - So when the calling application accesses the dll which in turn accesses the web service, it will check the SomeAssembly.dll.config?
- Well, the web service is on the web. But anytime the DLL tries to get values from the configuration, it'll first try the configuration file that matches it's own assembly name. (SomeAssembly.dll.config). If that doesn't exist, then it'll move to the executable's name.
Coding Light - Illuminated Ideas and Algorithms in Software
Coding Light Wiki • LinkedIn • ForumsBrowser - It might be cleaner to use two projects within your solution. one for your client app and one for the web service. There would be no confusion then
- I have tried that it doesn't seem to work.
I have removed the web service config from the unit test assembly's app.config.
I have then renamed the app.config file in the assembly which has the web service reference to Tapi.Core.dll.config (the assembly name is Tapi.Core)
Now when I run the unit test it fails because it cannot find the web service reference config information. - Yep. Unit tests are their own beast. You'll need another app.config file named after the unit test dll.Tapi.UnitTests.dll.config or something similar (assuming the compiled unit test assembly is called "Tapi.UnitTests.dll").
Coding Light - Illuminated Ideas and Algorithms in Software
Coding Light Wiki • LinkedIn • ForumsBrowser - I think we are talking about different things.
A = The assembly which contains the web reference
B = The assembly which calls A e.g. a website or a unit test assembly
I want A to read ITS OWN app.config file for settings it requires.
So when B calls A, A looks in its own App.Config file web service settings and executes.

