views:

56

answers:

2

Hi all

I use Castle Windsor in a couple of web apps just fine by putting the config data in web.config.

So when I decided to use it in a Windows Service I thought it would be a cinch. My app.config file looks like the following:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="castle" type="Castle.Windsor.Configuration.AppDomain.CastleSectionHandler,Castle.Windsor" />
  </configSections>
  ...various other stuff...
  <castle>
    <components>
      ...component listings...
    </components>
  </castle>
</configuration>

I'm creating my container like this:

WindsorContainer windsorContainer = new WindsorContainer(new XmlInterpreter());

But crazily, when the app runs I get

Could not find section 'castle' in the configuration file associated with this domain.
   at Castle.Core.Resource.ConfigResource..ctor(String sectionName)
   at Castle.Core.Resource.ConfigResource..ctor()
   at Castle.Windsor.Configuration.Interpreters.AbstractInterpreter..ctor()
   at Castle.Windsor.Configuration.Interpreters.XmlInterpreter..ctor()
   ...application stack trace...

I'm a bit bamboozled. Anyone got any tips?

Cheers

David

A: 

Well, let's hit the obvious. An executable will be using myprog.exe.config for it's configuration. The app.config should be copied to that filename and placed in the output folder with the .exe. Do you have that file with the service executable?

James Curran
Check..........
David
Why is there a minimum character limit on comments?! This site is mental.
David
does the file have the castle section (the one in output directory where you run your service from). You may hit some odd merge issues...
Krzysztof Koźmic
@Krzysztof: do you mean have I included the castle section in the app.config file? If so yes. Or do you mean something else?
David
I mean the resulting file in the output directory. Can you make sure that it does have the section?
Krzysztof Koźmic
+1  A: 

I seem to recall something about app.config files and windows services. Since the application that is actually "running" your service is svchost.exe and that exe exists in %windir%\system32, that is where you config file needs to be. Try placing it there (%windir%\system32) and see what happens.

Patrick Steele
The app reads other config data out of app.config just fine but it's possible that Castle is looking in the location you mention. I'll check it out and have a look.
David
I've got another error now, lol! I think that means your suggestion worked. You have answered my question, but this is not acceptable to me as a workaround so I'm going to look into alternative configuration options.
David