문제

I have a project (A) referencing a Service (B) via. a Service Reference.

That Service (B) has a reference to a DLL (lets call it Business.dll)

That DLL has it's own accommodating app.config which has some configuration that I would assume would be easily read whether being called internally (as a console app) or externally from Service (B).

Currently, this isn't working. The app.config (or, more specifically, the Business.dll.config file) is not being read at all, and:

(BusinessConfigurationSection)ConfigurationManager.GetSection("GroupName/SectionName");

is always null when called from project (A). Can I not save the Business.dll.config within the bin directory of Service (B), or am I doing something that simply is not possible? Is there a better way that I should be doing this?

Thanks.

도움이 되었습니까?

해결책

You can load a specific config file like this :

Configuration config;
ExeConfigurationFileMap ecfm = new ExeConfigurationFileMap();
ecfm.ExeConfigFilename = <your_config_file_path>;

config = ConfigurationManager.OpenMappedExeConfiguration(ecfm, ConfigurationUserLevel.None);
var mySection = (BusinessConfigurationSection)config.GetSection("GroupName/SectionName");

다른 팁

When you call from Project A, ConfigurationManager will always read from the ProjectA's App.config not from the DLLs

You can use following code to open DLL config,

  // Get the configuration file. The file name has 
      // this format appname.exe.config.
      System.Configuration.Configuration config =
        ConfigurationManager.OpenExeConfiguration(dllPath); //dll config
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top