Formular una preguntaFormular una pregunta
 

PreguntaUsing embedded App.Config

  • miércoles, 04 de noviembre de 2009 10:00TheLearner Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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

  • miércoles, 04 de noviembre de 2009 11:09Marcel Roma Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     

    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().

  • miércoles, 04 de noviembre de 2009 13:53TheLearner Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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?
  • miércoles, 04 de noviembre de 2009 13:56David M MortonMVP, ModeradorMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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 WikiLinkedInForumsBrowser
  • miércoles, 04 de noviembre de 2009 14:22Marcel Roma Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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.
  • miércoles, 04 de noviembre de 2009 15:40TheLearner Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    So when the calling application accesses the dll which in turn accesses the web service, it will check the SomeAssembly.dll.config?
  • miércoles, 04 de noviembre de 2009 15:45David M MortonMVP, ModeradorMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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 WikiLinkedInForumsBrowser
  • miércoles, 04 de noviembre de 2009 16:01jgalley Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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
  • jueves, 12 de noviembre de 2009 11:21TheLearner Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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.
  • jueves, 12 de noviembre de 2009 13:47David M MortonMVP, ModeradorMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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 WikiLinkedInForumsBrowser
  • jueves, 12 de noviembre de 2009 14:45TheLearner Medallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuarioMedallas del usuario
     
    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.