0

In a web.config file, I have a 3rd party settings section :

<configuration>
  <configSections>
    <sectionGroup name="TheProduct">
      <section name="TheSection" type="TheCompany.TheProduct.TheSectionConfigurationHandler, TheCompany.TheProduct, Version=1.0.0.0, Culture=neutral, PublicKeyToken=b1e9bee111e9429c" />
    </sectionGroup>
  </configSections>

  <TheProduct>
     <TheSection somevalue="true" />
  </TheProduct>
</configuration>

I want to read the value of this section from another application, but when I try to find the section, I always get null.

Here is my code :

var config = ConfigurationManager.OpenExeConfiguration(
    @"C:\inetpub\wwwroot\TheProduct\web.config"
    );
var settings = config.GetSection("TheProduct/TheSection"); // always null

What is the correct way to retrieve the config section ?

[Edit] If the calling app, which defines the same section, I can do :

var settings = ConfigurationManager.GetSection("TheProduct/TheSection");

and it's working. Mybe I'm not opening the web.config file using the correct way ?

Steve B
  • 36,818
  • 21
  • 101
  • 174

1 Answers1

0

Using the configuration manager requires that your application be able to instantiate the actual strongly-typed configuration objects. If you can't add a reference to the defining assembly, then your only choice is to use one of the XML api's (either System.Xml or System.Linq.Xml) to read it manually, in which case you won't be using the configuration manager at all.

Adam Robinson
  • 182,639
  • 35
  • 285
  • 343
  • I can't get the section of the remote app, but I can get the section of the current app. I think it's not a problem of extracting the value, but reading the section – Steve B Mar 06 '12 at 13:15