这是我第一次为worker角色的app.config创建自定义配置节类。当我在WorkerRole1项目中定义自定义部分类时,我能够成功地为worker角色成功,并且最初是app.config部分:
<configSections>
<sectionGroup name="environmentInfoGroup">
<section name="environmentInfo" type="WorkerRole1.EnvironmentInfoSection, WorkerRole1" allowLocation="true" allowDefinition="Everywhere" />
</sectionGroup>
</configSections>
但是,现在我将EnvironmentInfoSection类移动到MvcWebRole1.Models并将app.config更改为:
<configSections>
<sectionGroup name="environmentInfoGroup">
<section name="environmentInfo" type="MvcWebRole1.Models.EnvironmentInfoSection, MvcWebRole1.Models" allowLocation="true" allowDefinition="Everywhere" />
</sectionGroup>
</configSections>
在
行ConfigurationManager.GetSection("environmentInfoGroup/environmentInfo") as EnvironmentInfoSection;
我有一个例外
InnerException {"An error occurred creating the configuration section handler for environmentInfoGroup/environmentInfo: Could not load file or assembly 'MvcWebRole1.Models' or one of its dependencies. The system cannot find the file specified.
由于目前我的worker角色正在使用webRole中同一文件夹中的其他类,这是否意味着我无法在webRole和workerRole之间共享类以进行配置?或者有什么我错过了吗?
答案 0 :(得分:0)
我找到了一些不能直接用作问题答案的东西。 但是,我所做的是在工作站和Web角色项目中定义了两个相同的EnvironmentInfoSection,在app.config和Web.config中定义了两个相同的配置部分。
我注意到在app.config中:
<configSections>
<sectionGroup name="environmentInfoGroup">
<section name="environmentInfo" type="WorkerRole1.EnvironmentInfoSection, WorkerRole1" allowLocation="true" allowDefinition="Everywhere" />
</sectionGroup>
</configSections>
是正确的,但在Web.config(WebRole)
中<configSections>
<sectionGroup name="environmentInfoGroup">
<section name="environmentInfo" type="WebRole1.Models.EnvironmentInfoSection" allowLocation="true" allowDefinition="Everywhere" />
</sectionGroup>
</configSections>
是正确的方法。注意区别在于,在Web.config中,没有&#34;逗号&#34;在类型定义之后是命名空间。