locked
Reading app.config from another project RRS feed

  • Question

  • Hi

    I have a situation where I have two projects TFOS and BSLG. Both are console applikations within same solution.

    From inside the TFOS project I have a cs file (rnjbs.cs), when the solution in runned, the code within this class accesses another class (GetEmailData) which is located within the BSLG project. Within the BSLG project I have a app.config file. I'm trying to read values from this app.config file, from within the GetEmailData class.

    Normally this would not be a problem, however in this scenario I'm running from within the context of TFOS, due to this I cannot access the app.config file.

    The problem is that the path I get when using following methods to read app.config values: ConfigurationFileMap, ConfigurationManager.OpenMappedMachineConfiguration or ConfigurationManager.OpenExeConfigurationI keep getting the path for TFOS project and not the path for BSLG. The reason to this is because I'm running from within the context of TFOS. So my question is how do I read the values from app.config file, when running within the context of TFOS.

    I hope above was clearly explained, please let me know if further clarrification is needed.

    Monday, July 23, 2012 8:03 AM

Answers

  • You didn't mention that BSLG is a DLL. It's not smply possible. You need to change the Assembly's Configuration settings. Walk through the below code project article which puts some light on reading DLLs config files.

    http://www.codeproject.com/Articles/12228/App-Config-for-your-DLL

    I hope this helps.


    Please mark this post as answer if it solved your problem. Happy Programming!

    • Marked as answer by Lisa Zhu Friday, July 27, 2012 8:50 AM
    Monday, July 23, 2012 10:34 AM

All replies

  • Are both TFOS and BSLG are EXEs ? Or DLLs?

    If both of them are executables, then it is very easy. Just use ConfigurationManager.OpenExeConfiguration, passing BSLG.exe path as below

    string bslgApp = @"c:\Projects\TFOS\bin\debug\BSLG.exe";
    var configManager = ConfigurationManager.OpenExeConfiguration(bslgApp);

    Note that you must ensure the app.config for BSLG is present at the same location where BSLG.exe is present i.e. for above code BSLG.exe.config file should be at location c:\Projects\TFOS\bin\debug

    I hope this helps.


    Please mark this post as answer if it solved your problem. Happy Programming!

    Monday, July 23, 2012 8:32 AM
  • Hi

    The TFOS is an exe and the BSLG is a console app (dll).

    The procedure you have mentioned has already been tryed, however wth no resultset. 

    Monday, July 23, 2012 10:24 AM
  • You didn't mention that BSLG is a DLL. It's not smply possible. You need to change the Assembly's Configuration settings. Walk through the below code project article which puts some light on reading DLLs config files.

    http://www.codeproject.com/Articles/12228/App-Config-for-your-DLL

    I hope this helps.


    Please mark this post as answer if it solved your problem. Happy Programming!

    • Marked as answer by Lisa Zhu Friday, July 27, 2012 8:50 AM
    Monday, July 23, 2012 10:34 AM