2010-08-12 80 views
1

通过将配置数据放入web.config中,我可以在几个Web应用程序中使用Castle Windsor。Windows服务无法访问app.config中的Castle Windsor配置数据

因此,当我决定在Windows服务中使用它时,我认为它会很小。我的app.config文件如下所示:

<?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> 

我创建我的容器是这样的:

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

但是疯狂,当应用程序运行时,我得到

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... 

我'有点朦胧。任何人有任何提示?

干杯

大卫

回答

1

我似乎回想起一些关于app.config文件和windows服务的内容。由于实际“运行”您的服务的应用程序是svchost.exe,并且该exe文件存在于%windir%\ system32中,这就是您配置文件所需的位置。试着把它放在那里(%windir%\ system32),看看会发生什么。

+0

该应用从app.config中读取其他配置数据就好了,但Castle有可能在您提到的位置查找。我会检查一下并看看。 – David 2010-08-13 08:55:51

+0

我现在有另一个错误,哈哈!我认为这意味着你的建议奏效了。你已经回答了我的问题,但这是我无法接受的解决方法,因此我将考虑其他配置选项。 – David 2010-08-13 09:24:10

+0

我通过将windsor配置文件的位置传递给XmlInterpreter的构造函数(请参阅代码)来解决此问题。 – David 2011-06-30 12:12:53

0

那么,让我们击中了明显。可执行文件将使用myprog.exe.config进行配置。应该将app.config复制到该文件名并使用.exe放在输出文件夹中。你有服务可执行文件的那个文件吗?

+0

检查.......... – David 2010-08-12 16:10:39

+0

为什么评论的最小字符数限制?这个网站很精神。 – David 2010-08-12 16:10:57

+0

该文件是否具有城堡部分(输出目录中用于运行服务的部分)。你可能会遇到一些奇怪的合并问题... – 2010-08-12 22:38:01

相关问题