0

I have a desktop app which I need to test my windows service with.

The application just call a windows service class which handle my business, First it should load some data from app.config.

The app config is within the sevice project and I store my confugration in a custom section [ABCConfigurationSection]. Like ...

<ABCConfigurationSection>
    <ConnectSettings>
      <clear />
      <add key="HostIp" value="10.0.X.X"/>
    </ConnectSettings>
 </ABCConfigurationSection>

The main config section is like ..

<configuration>
  <configSections>
    <section name="ABCConfigurationSection" type="ABCConfiguration, App.Core" />
  </configSections>
</configuration>

When I retrive the configuration sections passing the "ABCConfigurationSection" as section name I got null ! Any idea about if the strcture of the app config is missing something

AshOoO
  • 1,108
  • 3
  • 13
  • 34

1 Answers1

0

In your configSections, for the section "ABCConfigurationSection", you declare that a type called "ABCConfiguration" is the type that handle your section.

This means, that in your code, you should define a class named ABCConfiguration derived from ConfigurationSection that read your section.

There are numerous details on this subject. This is a link to MSDN where a full example is given

Steve
  • 213,761
  • 22
  • 232
  • 286
  • I have that class and I use it with another application - web application - with no error and no problem. The problems just when using with in the win-service – AshOoO Apr 22 '12 at 14:04
  • Could you check the file properties of your config file?. This is a similar problem: [TypeInitializationException](http://stackoverflow.com/questions/3452077/typeinitializationexception-when-starting-windows-service-because-config-section) – Steve Apr 22 '12 at 14:21
  • I don't think, My file properties isn't like what in the referd post! it's not read only,not hidden even without the unblock button – AshOoO Apr 22 '12 at 15:04