在 Windows Server 2012 上的 .NET 4.0 上运行服务构建时出现 System.Configuration.ConfigurationException

Posted

技术标签:

【中文标题】在 Windows Server 2012 上的 .NET 4.0 上运行服务构建时出现 System.Configuration.ConfigurationException【英文标题】:System.Configuration.ConfigurationException when running a serviece build on .NET 4.0 on Windows Server 2012 【发布时间】:2015-11-18 13:38:20 【问题描述】:

美好的一天。

我有一个现有的 Windows 服务,它在使用 .NET 4.0 的 Windows Service 2003 上运行良好。我正在尝试在 Windows Service 2012 上安装相同的服务并成功。但是,当我运行该服务时,出现以下错误。我相信 Windows Server 支持 4.5 也包括 4.0,这是正确的吗?

谁能帮我确定我收到以下消息的原因?

Log Name:      Application
Source:        .NET Runtime
Date:          8/17/2015 5:56:56 AM
Event ID:      1026
Task Category: None
Level:         Error
Keywords:      Classic
User:          N/A
Computer:      usa0300vm1598.na.xerox.net
Description:
Application: ATLAS_LETTERPROCESS.SERVICE.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Configuration.ConfigurationErrorsException
Stack:
   at System.Configuration.ClientConfigurationSystem.EnsureInit(System.String)
   at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(System.String)
   at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(System.String)
   at System.Configuration.ConfigurationManager.get_AppSettings()
   at ATLAS_LETTERPROCESS.SERVICE.AtlasLetterProcess..ctor()
   at ATLAS_LETTERPROCESS.SERVICE.Program.Main()

事件 XML:

<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
  <System>
    <Provider Name=".NET Runtime" />
    <EventID Qualifiers="0">1026</EventID>
    <Level>2</Level>
    <Task>0</Task>
    <Keywords>0x80000000000000</Keywords>
    <TimeCreated SystemTime="2015-08-17T09:56:56.000000000Z" />
    <EventRecordID>58020</EventRecordID>
    <Channel>Application</Channel>
    <Computer>usa0300vm1598.na.xerox.net</Computer>
    <Security />
  </System>
  <EventData>
    <Data>Application: ATLAS_LETTERPROCESS.SERVICE.exe

Framework Version: v4.0.30319  
Description: The process was terminated due to an unhandled exception.

Exception Info: System.Configuration.ConfigurationErrorsException
Stack:
   at System.Configuration.ClientConfigurationSystem.EnsureInit(System.String)
   at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(System.String)
   at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(System.String)
   at System.Configuration.ConfigurationManager.get_AppSettings()
   at ATLAS_LETTERPROCESS.SERVICE.AtlasLetterProcess..ctor()
   at ATLAS_LETTERPROCESS.SERVICE.Program.Main()
</Data>
  </EventData>
</Event>

下面是当前的app.config文件

<?xml version="1.0"?>
<configuration>
  <configSections>
    <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
      <section name="ATLAS_LETTERPROCESS.Common.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    </sectionGroup>
  </configSections>
  <connectionStrings>
    <add name="Intentionally Hidden" connectionString="metadata=res://*/AtlasLetterProcess.csdl|res://*/AtlasLetterProcess.ssdl|res://*/AtlasLetterProcess.msl;provider=Oracle.DataAccess.Client;provider connection string=&quot;DATA SOURCE=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = Intentionally Hidden)(PORT = Intentionally Hidden))) (CONNECT_DATA = (SERVICE_NAME = Intentionally Hidden)));User Id= Intentionally Hidden;Password=Intentionally Hidden;&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
  <oracle.dataaccess.client>
    <settings>

      <add name="Intentionally Hidden" value="implicitRefCursor bindinfo='mode=Output'"/>

      <add name="Intentionally Hidden" value="implicitRefCursor metadata='ColumnName=TL_LETTER_ID;
           BaseColumnName=TL_LETTER_ID; BaseSchemaName=CMS_USER;BaseTableName=TBL_LETTER;
           NativeDataType=number;ProviderType=Int32'"/>

      <add name="Intentionally Hidden" value="implicitRefCursor metadata='ColumnName=TL_ATLAS_KEY_ID;
           BaseSchemaName=CMS_USER;BaseTableName=TBL_LETTER;NativeDataType=varchar2;ProviderType=varchar2;ProviderDBType=String;
                 DataType=System.String;AllowDBNull=true'"/>

      <add name="Intentionally Hidden" value="implicitRefCursor metadata='ColumnName=TL_INPUT_XML;
           BaseSchemaName=CMS_USER;BaseTableName=TBL_LETTER;
           NativeDataType=clob;ProviderType=Clob'"/>

      <add name="Intentionally Hidden" value="implicitRefCursor metadata='ColumnName=TL_DART_URL;BaseSchemaName=CMS_USER;
                 BaseTableName=TBL_LETTER;NativeDataType=varchar2;ProviderType=Varchar2;ProviderDBType=String;
                 DataType=System.String;AllowDBNull=true'"/>

      <add name="Intentionally Hidden" value="implicitRefCursor metadata='ColumnName=TL_STATUS;BaseSchemaName=CMS_USER;
                 BaseTableName=TBL_LETTER;NativeDataType=char;ProviderType=char;ProviderDBType=String;ColumnSize=2;
                 DataType=System.String;AllowDBNull=true'"/>

      <add name="Intentionally Hidden" value="implicitRefCursor metadata='ColumnName=TL_TYPE;
                 BaseSchemaName=CMS_USER;BaseTableName=TBL_LETTER;NativeDataType=varchar2;ProviderType=varchar2;ProviderDBType=String;
                 DataType=System.String;AllowDBNull=true'"/>

      <add name="Intentionally Hidden" value="implicitRefCursor metadata='ColumnName=TL_MODE;BaseSchemaName=CMS_USER;
                 BaseTableName=TBL_LETTER;NativeDataType=char;ProviderType=char;ProviderDBType=String;ColumnSize=1;
                 DataType=System.String;AllowDBNull=true'"/>

      <add name="Intentionally Hidden" value="implicitRefCursor metadata='ColumnName=TL_REMARKS;BaseSchemaName=CMS_USER;
                 BaseTableName=TBL_LETTER;NativeDataType=varchar2;ProviderType=varchar2;ProviderDBType=String;ColumnSize=2000;
                 DataType=System.String;AllowDBNull=true'"/>

      <add name="Intentionally Hidden" value="implicitRefCursor metadata='ColumnName=TL_TASK_ID;BaseSchemaName=CMS_USER;
                 BaseTableName=TBL_LETTER;NativeDataType=varchar2;ProviderType=varchar2;ProviderDBType=String;ColumnSize=50;
                 DataType=System.String;AllowDBNull=true'"/>

      <add name="Intentionally Hidden" value="implicitRefCursor metadata='ColumnName=TEMPLATE_NAME;BaseSchemaName=CMS_USER;
                 BaseTableName=TBL_LETTER;NativeDataType=varchar2;ProviderType=varchar2;ProviderDBType=String;ColumnSize=100;
                 DataType=System.String;AllowDBNull=true'"/>

      <add name="Intentionally Hidden" value="implicitRefCursor metadata='ColumnName=TEMPLATE_PATH;BaseSchemaName=CMS_USER;
                 BaseTableName=TBL_LETTER;NativeDataType=varchar2;ProviderType=varchar2;ProviderDBType=String;ColumnSize=2000;
                 DataType=System.String;AllowDBNull=true'"/>

      <add name="Intentionally Hidden" value="implicitRefCursor metadata='ColumnName=PULL_DART_INVOICE;BaseSchemaName=CMS_USER;
                 BaseTableName=TBL_LETTER;NativeDataType=varchar2;ProviderType=char;ProviderDBType=String;ColumnSize=1;
                 DataType=System.String;AllowDBNull=true'"/>

      <add name="Intentionally Hidden" value="implicitRefCursor metadata='ColumnName=DESCRIPTION;BaseSchemaName=CMS_USER;
                 BaseTableName=TBL_LETTER;NativeDataType=varchar2;ProviderType=varchar2;ProviderDBType=String;ColumnSize=100;
                 DataType=System.String;AllowDBNull=true'"/>

      <add name="Intentionally Hidden" value="implicitRefCursor metadata='ColumnName=TEMPLATE_IDENTIFIER_TYPE;BaseSchemaName=CMS_USER;
                 BaseTableName=TBL_LETTER;NativeDataType=varchar2;ProviderType=varchar2;ProviderDBType=String;ColumnSize=100;
                 DataType=System.String;AllowDBNull=true'"/>
    </settings>
  </oracle.dataaccess.client>
  <appSettings>

    <add key="CCLLetterPath" value="D:\Atlas_Collection_Services\AtlasLetterProcess\Output\CCLLetters\"/>
    <add key="AutoLetterPath" value="D:\Atlas_Collection_Services\AtlasLetterProcess\Output\AutoLetters\"/>
    <add key="OnDemandPath" value="D:\Atlas_Collection_Services\AtlasLetterProcess\Output\OnDemandLetters\"/>
    <add key="AutoStopPath" value="D:\Atlas_Collection_Services\AtlasLetterProcess\Output\AutoStopLetters\"/>
    <add key="XSDPath" value="D:\Atlas_Collection_Services\AtlasLetterProcess\XSD\LetterProcess.xsd"/>
    <add key="LogFilePath" value="D:\Atlas_Collection_Services\AtlasLetterProcess\Log\"/>
    <add key="LogFileName" value="ATLAS_LETTERPROCESS"/>
    <add key="HeaderImage" value="D:\Atlas_Collection_Services\AtlasLetterProcess\Header.jpg"/>
    <add key="DeleteFiles" value="Y"/>
    <add key="ArchivePath" value="D:\Atlas_Collection_Services\AtlasLetterProcess\Archive\"/>
    <!-- Print Center Configurations-->
    <add key="ServerAddress" value="Intentionally Hidden" />
    <add key="UserName" value="Intentionally Hidden" />
    <add key="Password" value="Intentionally Hidden" />
    <add key="LicenseKey" value="Intentionally Hidden" />
    <add key="LicenseOwner" value="Intentionally Hidden" />
    <add key="ChangeWorkingDirectory" value="/collectltr/Prod/" />
    <add key="ServerPort" value="22" />
    <!--Email Details-->
    <add key="SMTPServer" value="Intentionally Hidden" />
    <add key="EmailSupportFrom" value="AtlasLetterProcessProd@Intentionally Hidden"/>
    <add key="EmailSupportTo" value="Intentionally Hidden@Intentionally Hidden"/>
    <add key="EmailSupportCC" value=""/>
    <add key="EmailSupportBCC" value=""/>
    <add key="EmailSubject" value="Atlas LetterProcess(Prod): Error in letter process service."/>
    <add key ="ErrorStartLine" value = "****************** Error Message ******************" />
    <add key ="EndLine" value = "***************************************************" />
    <!--ATLAS-->
    <add key="AtlasUsername" value="Intentionally Hidden" />
    <add key="AtlasPassword" value="Intentionally Hidden" />
    <add key="AtlasSessionType" value="Stateless" />
    <add key="AtlasExpirationHours" value="10" />
    <add key="AtalasServiceURL"  value="http://Intentionally Hidden:8080/eai_enu/start.swe?SWEExtSource=WebService&amp;SWEExtCmd=Execute&amp;WSSOAP=1"/>
    <!--Service Timing-->
    <add key="AutoMode" value="ON" />
    <add key="ServiceStartTime" value="01:00" />
    <add key="ServiceEndTime" value="23:00" />
    <add key="ServiceInterval" value="60000" />
    <add key="ServiceDay" value="1,2,3,4,5,6,0" />
    <!--Mon-1,Tue-2,Wed-3,Thr-4,Fri-5,Sat-6,Sun-0-->
    <!--Dart Service configurations-->
    <add key="DARTServiceURL" value="Intentionally Hidden"/>
    <add key="DartUsername" value="Intentionally Hidden"/>
    <add key="DartPassword" value="Intentionally Hidden"/>
    <add key="PartitionLimit" value="1000" />
    <add key="ExcludeInvoiceCodes" value="78,79,RD,TD,SD" />

  </appSettings>
  <applicationSettings>
    <ATLAS_LETTERPROCESS.Common.Properties.Settings>
      <setting name="ATLAS_LETTERPROCESS_Common_DARTWebService_DARTWebServiceService"
          serializeAs="String">
        <value>Intentionally Hidden</value>
      </setting>
    </ATLAS_LETTERPROCESS.Common.Properties.Settings>
  </applicationSettings>
  <system.web>
    <webServices>
      <soapExtensionTypes>
        <add type="ATLAS_LETTERPROCESS.SoapExtension.SiebelSoapExtension, ATLAS_LETTERPROCESS.SoapExtension" />
      </soapExtensionTypes>
    </webServices>
    <membership defaultProvider="ClientAuthenticationMembershipProvider">
      <providers>
        <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
      </providers>
    </membership>
    <roleManager defaultProvider="ClientRoleProvider" enabled="true">
      <providers>
        <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
      </providers>
    </roleManager>
  </system.web>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
  </startup>
</configuration>

【问题讨论】:

你的 app.config 文件有错误 向我们展示您的 exe.config 文件(appSettings 部分) 我从 app.config 添加了内容(注意:有些值是故意隐藏的) 对这个问题有什么帮助吗?谢谢 【参考方案1】:

我能够使用一个简单的控制台应用程序并使用您那里的配置文件作为 App.config 来复制此问题。

例如,在控制台应用程序中,我只有以下两行 -

class Program

    static void Main(string[] args)
    
        var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        var abc = ConfigurationManager.AppSettings["abc"];
    

执行上述程序后,我得到如下所示的错误 -

   at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
   at System.Configuration.ClientConfigurationSystem.PrepareClientConfigSystem(String sectionName)
   at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String sectionName)
   at System.Configuration.ConfigurationManager.get_AppSettings()
   at ExperimentConsoleApp.Program.Main(String[] args) 

但是当我查看内部异常时,我会看到以下错误 -

Unrecognized configuration section oracle.dataaccess.client. 

这很好,因为我没有安装正确的组件,但配置部分没有指定组件,并验证我注释掉了 oracle 数据访问并且它有效。我还尝试安装 oracle 托管数据访问组件,并且正如预期的那样,它在 web.config 的配置部分中添加了配置。

配置部分缺少 oracle 数据访问配置。例如下面是 Oracle 管理的数据访问 -

<configSections>

    <section name="oracle.manageddataaccess.client"

      type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.1.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />  

  </configSections>

【讨论】:

使用这种测试方法帮助我解决了另一个与 app.config 相关的问题。

以上是关于在 Windows Server 2012 上的 .NET 4.0 上运行服务构建时出现 System.Configuration.ConfigurationException的主要内容,如果未能解决你的问题,请参考以下文章

Windows服务平台上的WCFNoSupportedException在Windows Server 2012 R2上

带有 PHP 版本 5.6.14 的 Windows Server 2012 上的 OCI 连接问题

在 Windows Server 2012 上的 .NET 4.0 上运行服务构建时出现 System.Configuration.ConfigurationException

powershell 这将获得Windows Server 2012 r2上的所有Windows功能及其状态

无法通过 Windows 2012 上的系统 dsn 使用 ODBC 连接连接到 SQL Server 2008

如何安装windows server 2012