none
Can I manually specify my *.config file RRS feed

  • Question

  • using .NET 2.0

    We have a custom built "service" that will loads and runs assemblies adhering to a specific Interface.  To configure these assemblies, our framework exposes a gui interface to populate public properties.  I think you get the idea.

    I have some logic that I want to run with this service but it references another assembly that is looking for appSettings key/values.  Unfortunately my.dll.config is never read.  I can use ConfigurationManager to open the file and reads its value, but that doesn't help with the referenced assembly.

    Is it possible to "load up a config file by path so that the ConfigurationManager.appsettings works as expected?

    Thursday, June 4, 2009 8:49 PM

Answers

  • Unfortunately, no.  The ConfigurationManager.AppSettings is always going to return the application's specific app.config file.  You'll have to use the OpenExeConfiguration method to retrieve the Configuration object.  You may want to consider abstracting this all out into a custom class just to make coding easier.
    David Morton - http://blog.davemorton.net/ - @davidmmorton
    • Marked as answer by kevcoder Thursday, June 4, 2009 9:18 PM
    Thursday, June 4, 2009 9:15 PM
    Moderator

All replies

  • Unfortunately, no.  The ConfigurationManager.AppSettings is always going to return the application's specific app.config file.  You'll have to use the OpenExeConfiguration method to retrieve the Configuration object.  You may want to consider abstracting this all out into a custom class just to make coding easier.
    David Morton - http://blog.davemorton.net/ - @davidmmorton
    • Marked as answer by kevcoder Thursday, June 4, 2009 9:18 PM
    Thursday, June 4, 2009 9:15 PM
    Moderator
  • I figured as much but hoped that somebody would pull something amazing out of the ole ____ and save my day.

    Thanks!

    Thursday, June 4, 2009 9:21 PM
  • Hi kevcoder,

     

    From your description, I think you cannot modify the referenced assembly.  If so, here is a potential workaround for your references.   

     

    You can create a dedicated app domain to load the referenced assembly and set the configuration file to the certain dll.config.  For additional information and code snippets, please refer to http://codebetter.com/blogs/jeffrey.palermo/archive/2005/05/04/73198.aspx.  You can consider creating another class library which contains a wrapper class like the Foo class in the code example, to share data between different app domains.  

     

     

    Have a nice day, kevcoder and David!

     

     

    Best Regards,
    Lingzhi


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Send us any feedback you have about the help from MSFT at fbmsdn@microsoft.com.
    Friday, June 5, 2009 6:02 AM
    Moderator