在webrole的model文件夹中定义worker角色的app.config节处理程序
本文关键字:config app 处理 程序 角色 定义 model webrole 文件夹 worker | 更新日期: 2023-09-27 18:18:27
这是我第一次为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。并将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.
因为目前我的工人角色是使用其他类从同一个文件夹在webRole,这是否意味着我不能共享类从webRole到workerRole配置的东西?还是我错过了什么?
我发现了一些不能直接作为问题答案的东西。然而,我所做的是在worker和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。配置(WebRole)
<configSections>
<sectionGroup name="environmentInfoGroup">
<section name="environmentInfo" type="WebRole1.Models.EnvironmentInfoSection" allowLocation="true" allowDefinition="Everywhere" />
</sectionGroup>
</configSections>
是正确的方法。注意不同之处在于Web。