编程语言
首页 > 编程语言> > c#-‘System.ServiceModel.Diagnostics.TraceUtility’的类型初始值设定项引发异常

c#-‘System.ServiceModel.Diagnostics.TraceUtility’的类型初始值设定项引发异常

作者:互联网

我有以下配置.当我尝试启动我的应用程序时出现以下错误:

‘System.ServiceModel.Diagnostics.TraceUtility’的类型初始值设定项引发了异常

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <system.serviceModel>
        <bindings>
            <basicHttpBinding>
                <binding name="BasicHttpBinding_InterFaceName" maxReceivedMessageSize="2147483647">
                    <security mode="TransportWithMessageCredential" />
                </binding>
                <binding name="BasicHttpBinding_IEventSubscriptionCallback">
                    <security mode="TransportWithMessageCredential" />
                </binding>
                <binding name="BasicHttpBinding_IFolders">
                    <security mode="TransportWithMessageCredential" />
                </binding>
                <binding name="BasicHttpBinding_IBrowse">
                    <security mode="TransportWithMessageCredential" />
                </binding>
                <binding name="BasicHttpBinding_IConfig">
                    <security mode="TransportWithMessageCredential" />
                </binding>
                <binding name="BasicHttpBinding_IData">
                    <security mode="TransportWithMessageCredential" />
                </binding>
                <binding name="BasicHttpBinding_IDataAccess">
                    <security mode="TransportWithMessageCredential" />
                </binding>
                <binding name="BasicHttpBinding_IMetadata">
                    <security mode="TransportWithMessageCredential" />
                </binding>
                <binding name="BasicHttpBinding_IServiceControl">
                    <security mode="TransportWithMessageCredential" />
                </binding>
            </basicHttpBinding>
        </bindings>
        <client>
            <endpoint address="https://EndPointAddress/InterFaceName"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_InterFaceName"
                contract="ClientNameBF.InterFaceName" name="BasicHttpBinding_InterFaceName" />
            <endpoint address="https://EndPointAddress/IEventSubscriptionCallback"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IEventSubscriptionCallback"
                contract="ClientNameBF.IEventSubscriptionCallback" name="BasicHttpBinding_IEventSubscriptionCallback" />
            <endpoint address="https://EndPointAddress/IFolders"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IFolders"
                contract="ClientNameBF.IFolders" name="BasicHttpBinding_IFolders" />
            <endpoint address="https://EndPointAddress/IBrowse"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IBrowse"
                contract="ClientNameBF.IBrowse" name="BasicHttpBinding_IBrowse" />
            <endpoint address="https://EndPointAddress/IConfig"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IConfig"
                contract="ClientNameBF.IConfig" name="BasicHttpBinding_IConfig" />
            <endpoint address="https://EndPointAddress/IData"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IData"
                contract="ClientNameBF.IData" name="BasicHttpBinding_IData" />
            <endpoint address="https://EndPointAddress/IDataAccess"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDataAccess"
                contract="ClientNameBF.IDataAccess" name="BasicHttpBinding_IDataAccess" />
            <endpoint address="https://EndPointAddress/IMetadata"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IMetadata"
                contract="ClientNameBF.IMetadata" name="BasicHttpBinding_IMetadata" />
            <endpoint address="https://EndPointAddress/IServiceControl"
                binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IServiceControl"
                contract="ClientNameBF.IServiceControl" name="BasicHttpBinding_IServiceControl" />
        </client>
    </system.serviceModel>
  <applicationSettings>
    <PKISettings>
      <setting name="CertThumbPrint" serializeAs="String">
        <value>Something</value>
      </setting>
    </PKISettings>
    <UserSettings>
      <setting name="User1" serializeAs="String">
        <value>Users</value>
      </setting>
      <setting name="Pass1" serializeAs="String">
        <value>JT1yn4Y9SG</value>
      </setting>
      <setting name="User2" serializeAs="String">
        <value>Smthings</value>
      </setting>
      <setting name="Pass2" serializeAs="String">
        <value>sndkjhjsf</value>
      </setting>
      <setting name="User3" serializeAs="String">
        <value>Usr</value>
      </setting>
      <setting name="Pass3" serializeAs="String">
        <value>dgfg/ndfgdfg</value>
      </setting>
      <setting name="User4" serializeAs="String">
        <value>dfgfgdgf</value>
      </setting>
      <setting name="Pass4" serializeAs="String">
        <value>dsfgfg=</value>
      </setting>
    </UserSettings>
  </applicationSettings>
</configuration>

解决方法:

您的配置中缺少configSections(与WCF完全无关).例如(必须是配置元素下的第一个孩子):

<configuration>
  <configSections>
      <sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
          <section name="PKISettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
          <section name="UserSettings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
      </sectionGroup>
  </configSections>

标签:app-config,wcf,c,net
来源: https://codeday.me/bug/20191118/2028594.html