c#-在Windows Server 2012上的.NET 4.0上运行服务生成时出现System.Configuration.ConfigurationException

美好的一天.我有一个现有的Windows服务,该服务在使用.NET 4.0的Windows Service 2003上运行良好.我试图在Windows Service 2012上安装相同的服务,并且成功.但是,当我运行该服务时,出现以下错误.我相信Windows Server...

美好的一天.

我有一个现有的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>

解决方法:

我能够使用一个简单的控制台应用程序并使用您在那里拥有的Config文件作为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. 

这可能非常好,因为我没有安装正确的组件,但是configsections没有指定组件,并且要验证我已注释掉oracle数据访问权限并且它可以工作.我还尝试安装oracle托管数据访问组件,并按预期将其配置添加到web.config的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>

本文标题为:c#-在Windows Server 2012上的.NET 4.0上运行服务生成时出现System.Configuration.ConfigurationException

基础教程推荐