“创建配置节处理程序时发生错误” -

时间:2013-05-03 17:02:38

标签: c# service app-config

我们的测试环境中出现了一个奇怪的错误,其中包含自定义配置部分。

这适用于在开发和测试环境中使用SQL Server 2008在Enterprise Server 2008 r2 64位上运行的Windows服务。

此部分配置我们的共享代码库,以便在处理错误并使用以下代码发布时向相关方发送电子邮件:

catch(Exception ex)
{
    ExceptionManager.Publish(ex);
}

错误细节(完整细节 - 名称已更改以保留无辜者)

4   <configSections>
5       <section name="exceptionManagement"
6                type="Company.Shared.ExceptionManagement.ExceptionManagerSectionHandler, Company.Shared" />
7   </configSections>
8   <exceptionManagement>
9       <publisher assembly="Company.Shared" type="Company.Shared.ExceptionManagement.DefaultPublisher"
10                 logName="CPODSOracleDataExchange" applicationName="CPODSOracleDataExchange Service" />
11      <publisher assembly="Company.Shared" type="Company.Shared.ExceptionManagement.ExceptionManagerSMTPPublisher"
12                 from="CPODSOracleDataExchangeService@Company.com"
13                 defaultRecipients="dev1@Company.com,dev2@Company.com"
14                 applicationName="CPODSOracleDataExchange Service" />
15  </exceptionManagement>


1) Exception Information
*********************************************
Exception Type: System.Configuration.ConfigurationErrorsException
Message: An error occurred creating the configuration section handler for exceptionManagement: Request failed. (E:\CITApps\Services\CPODS.OracleDataExchangeService\Company.CPODS.OracleDataExchangeService.exe.Config line 5)
BareMessage: An error occurred creating the configuration section handler for exceptionManagement: Request failed.
Filename: E:\CITApps\Services\CPODS.OracleDataExchangeService\Company.CPODS.OracleDataExchangeService.exe.Config
Line: 5
Errors: System.Configuration.ConfigurationException[]
Data: System.Collections.ListDictionaryInternal
TargetSite: System.Configuration.FactoryRecord FindAndEnsureFactoryRecord(System.String, Boolean ByRef)
HelpLink: NULL
Source: System.Configuration

StackTrace Information
*********************************************
   at System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String configKey, Boolean& isRootDeclaredHere)
   at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
   at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
   at Company.Shared.ExceptionManagement.ExceptionManager.Publish(Exception exception, NameValueCollection additionalInfo)

2) Exception Information
*********************************************
Exception Type: System.Security.SecurityException
Action: Demand
PermissionType: System.Security.PermissionSet
FirstPermissionThatFailed: NULL
PermissionState: <PermissionSet class="System.Security.PermissionSet"
version="1"
Unrestricted="true"/>

Demanded: <PermissionSet class="System.Security.PermissionSet"
version="1"
Unrestricted="true"/>

GrantedSet: 
RefusedSet: 
DenySetInstance: NULL
PermitOnlySetInstance: <PermissionSet class="System.Security.PermissionSet"
version="1">
<IPermission class="System.Security.Permissions.FileDialogPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Access="Open"/>
<IPermission class="System.Security.Permissions.IsolatedStorageFilePermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Allowed="ApplicationIsolationByUser"
UserQuota="1024000"/>
<IPermission class="System.Security.Permissions.SecurityPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Flags="Execution"/>
<IPermission class="System.Security.Permissions.UIPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"
version="1"
Window="SafeTopLevelWindows"
Clipboard="OwnClipboard"/>
<IPermission class="System.Drawing.Printing.PrintingPermission, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
version="1"
Level="SafePrinting"/>
<IPermission class="System.Security.Permissions.MediaPermission, WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
version="1"
Audio="SafeAudio"
Video="SafeVideo"
Image="SafeImage"/>
<IPermission class="System.Security.Permissions.WebBrowserPermission, WindowsBase, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
version="1"
Level="Safe"/>
</PermissionSet>

FailedAssemblyInfo: NULL
Method: Void InitWithRestrictedPermissions(System.Configuration.RuntimeConfigurationRecord, System.Configuration.FactoryRecord)
Zone: NoZone
Url: 
Message: Request failed.
Data: System.Collections.ListDictionaryInternal
TargetSite: System.Object CreateInstance(System.RuntimeType, Boolean, Boolean, Boolean ByRef, System.RuntimeMethodHandleInternal ByRef, Boolean ByRef)
HelpLink: NULL
Source: mscorlib

StackTrace Information
*********************************************
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Configuration.TypeUtil.CreateInstanceWithReflectionPermission(Type type)
   at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.Init(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)
   at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.InitWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord)
   at System.Configuration.RuntimeConfigurationRecord.CreateSectionFactory(FactoryRecord factoryRecord)
   at System.Configuration.BaseConfigurationRecord.FindAndEnsureFactoryRecord(String configKey, Boolean& isRootDeclaredHere)

有问题的配置文件部分(带行号):

4   <configSections>
5       <section name="exceptionManagement"
6                type="Company.Shared.ExceptionManagement.ExceptionManagerSectionHandler, Company.Shared" />
7   </configSections>
8   <exceptionManagement>
9       <publisher assembly="Company.Shared" type="Company.Shared.ExceptionManagement.DefaultPublisher"
10                 logName="CPODSOracleDataExchange" applicationName="CPODSOracleDataExchange Service" />
11      <publisher assembly="Company.Shared" type="Company.Shared.ExceptionManagement.ExceptionManagerSMTPPublisher"
12                 from="CPODSOracleDataExchangeService@Company.com"
13                 defaultRecipients="dev1@Company.com,dev2@Company.com"
14                 applicationName="CPODSOracleDataExchange Service" />
15  </exceptionManagement>

这个完全相同的配置在我们的DEV环境中正常工作。据我所知,这些是相同的环境,两种服务都在相同的代码库下运行。

关于权限失败的任何想法?我们正在做的一件事是创建自定义日志,但即使我们删除了尝试写入不存在的自定义日志的默认发布者,该过程仍然会失败。

3 个答案:

答案 0 :(得分:4)

原来这是一个模糊的安装问题。

我们使用旧的exe卸载了服务,并使用64位4.0框架重新安装,问题就消失了。

答案 1 :(得分:0)

它是构建配置中的框架设置

答案 2 :(得分:0)

与您的方案没有直接关系,但如果您在尝试从网络共享运行.NET 4.0应用程序时遇到相同的异常,则需要安装此修补程序: http://support.microsoft.com/kb/2580188