我在几个web应用程序中使用Castle Windsor,只需将配置数据放在web.config中即可。
因此,当我决定在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...我有点糊涂了。有人有什么建议吗?
干杯
大卫
发布于 2010-08-13 10:33:30
我似乎想起了一些关于app.config文件和windows服务的事情。由于实际“运行”您的服务的应用程序是svchost.exe,且该可执行文件存在于%windir%\system32中,因此您需要将配置文件放在该位置。试着把它放在那里(%windir%\system32),看看会发生什么。
发布于 2010-08-12 23:59:25
好吧,让我们直截了当地说。可执行文件将使用myprog.exe.config进行配置。应将app.config复制到该文件名,并与.exe一起放在输出文件夹中。您有包含服务可执行文件的文件吗?
发布于 2020-06-26 16:10:31
为了解决windows服务无法访问配置数据或分区找不到适合我的内容的问题,以这种方式创建了容器: new WindsorContainer(new XmlInterpreter(new ConfigResource(“ConfigResource”)
https://stackoverflow.com/questions/3469515
复制相似问题