Ask a questionAsk a question
 

QuestionUsing embedded App.Config

  • Wednesday, November 04, 2009 10:00 AMTheLearner Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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?

All Replies

  • Wednesday, November 04, 2009 11:09 AMMarcel Roma Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

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

  • Wednesday, November 04, 2009 1:53 PMTheLearner Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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?
  • Wednesday, November 04, 2009 1:56 PMDavid M MortonMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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
  • Wednesday, November 04, 2009 2:22 PMMarcel Roma Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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.
  • Wednesday, November 04, 2009 3:40 PMTheLearner Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    So when the calling application accesses the dll which in turn accesses the web service, it will check the SomeAssembly.dll.config?
  • Wednesday, November 04, 2009 3:45 PMDavid M MortonMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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
  • Wednesday, November 04, 2009 4:01 PMjgalley Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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
  • Thursday, November 12, 2009 11:21 AMTheLearner Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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.
  • Thursday, November 12, 2009 1:47 PMDavid M MortonMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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
  • Thursday, November 12, 2009 2:45 PMTheLearner Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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.