Domanda

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.

È stato utile?

Soluzione

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");

Altri suggerimenti

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
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top