title: An unhandled exception of type 'System.TypeInitializationException' occurred in System.ServiceModel.dll
body: <p>I am trying to debug/log SOAP messages for C# WCF Project, but I get:</p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.TypeInitializationException' occurred in System.ServiceModel.dll <br/>
     <br/>
    Additional information: The type initializer for 'System.ServiceModel.Diagnostics.TraceUtility' threw an exception.</p>
  </blockquote>
  
  <p>My <code>app.config</code> file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
  
    &lt;system.diagnostics&gt;
      &lt;sources&gt;
        &lt;source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="True"&gt;
          &lt;listeners&gt;
            &lt;add name="xml"&gt;&lt;/add&gt;
          &lt;/listeners&gt;
        &lt;/source&gt;
      &lt;/sources&gt;
    &lt;/system.diagnostics&gt;
  
    &lt;startup&gt;
      &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" /&gt;
    &lt;/startup&gt;
  
    &lt;source name="System.ServiceModel.MessageLogging"&gt;
      &lt;listeners&gt;
        &lt;add name="xml"/&gt;
      &lt;/listeners&gt;
    &lt;/source&gt;
  
    &lt;source name="myUserTraceSource"
          switchValue="Information, ActivityTracing"&gt;
      &lt;listeners&gt;
        &lt;add name="xml"/&gt;
      &lt;/listeners&gt;
    &lt;/source&gt;
  
    &lt;sharedListeners&gt;
      &lt;add name="xml"
           type="System.Diagnostics.XmlWriterTraceListener"
                 initializeData="C:\users\scott\Traces.svclog" /&gt;
    &lt;/sharedListeners&gt;
  
    &lt;system.serviceModel&gt;
      &lt;behaviors&gt;
  
        &lt;serviceBehaviors&gt;
          &lt;behavior name="debug"&gt;
            &lt;serviceDebug includeExceptionDetailInFaults="true"/&gt;
          &lt;/behavior&gt;
        &lt;/serviceBehaviors&gt;
  
        &lt;endpointBehaviors&gt;
          &lt;behavior name="endpointCredentialBehavior"&gt;
            &lt;clientCredentials&gt;
              &lt;clientCertificate findValue="attdev.drsllc.net"
                                 x509FindType="FindBySubjectName"
                                 storeLocation="LocalMachine"
                                 storeName="TrustedPeople" /&gt;
            &lt;/clientCredentials&gt;
          &lt;/behavior&gt;
        &lt;/endpointBehaviors&gt;
      &lt;/behaviors&gt;
  
      &lt;bindings&gt;
        &lt;basicHttpBinding&gt;
          &lt;binding name="CreateBillingDisputeSoapHttpBinding"&gt;
            &lt;security mode="Transport" /&gt;
          &lt;/binding&gt;
  
          &lt;binding name="CreateBillingReportSoapHttpBinding"&gt;
            &lt;security mode="Transport" /&gt;
          &lt;/binding&gt;
  
          &lt;binding name="EchoSoapHttpBinding"&gt;
            &lt;security mode="Transport" &gt;
              &lt;transport clientCredentialType="Certificate"  /&gt;
            &lt;/security&gt;
          &lt;/binding&gt;
  
          &lt;binding name="InquireBillingDisputeDetailsSoapHttpBinding"&gt;
            &lt;security mode="Transport" /&gt;
          &lt;/binding&gt;
  
          &lt;binding name="InquireBillingInvoiceDetailsSoapHttpBinding"&gt;
            &lt;security mode="Transport" /&gt;
          &lt;/binding&gt;
  
          &lt;binding name="InquireBillingInvoiceSummarySoapHttpBinding"&gt;
            &lt;security mode="Transport" /&gt;
          &lt;/binding&gt;
  
          &lt;binding name="InquireEnterpriseOrderDetailsSoapHttpBinding"&gt;
            &lt;security mode="Transport" /&gt;
          &lt;/binding&gt;
  
          &lt;binding name="InquireEnterpriseOrderListSoapHttpBinding"&gt;
            &lt;security mode="Transport" &gt;
              &lt;transport clientCredentialType="Certificate"  /&gt;
            &lt;/security&gt;
          &lt;/binding&gt;
  
          &lt;binding name="InquireEnterpriseOrderStatusSoapHttpBinding"&gt;
            &lt;security mode="Transport" /&gt;
          &lt;/binding&gt;
  
          &lt;binding name="InquireNetworkProductCatalogSoapHttpBinding"&gt;
            &lt;security mode="Transport" /&gt;
          &lt;/binding&gt;
  
          &lt;binding name="InquireNetworkProductPriceQuoteSoapHttpBinding"&gt;
            &lt;security mode="Transport" /&gt;
          &lt;/binding&gt;
  
          &lt;binding name="InquireNetworkProductRateCardSoapHttpBinding"&gt;
            &lt;security mode="Transport" /&gt;
          &lt;/binding&gt;
  
          &lt;binding name="InquireSLACreditClaimStatusSoapHttpBinding"&gt;
            &lt;security mode="Transport" /&gt;
          &lt;/binding&gt;
  
          &lt;binding name="InquireSLANetworkCreditClaimStatusSoapHttpBinding"&gt;
            &lt;security mode="Transport" /&gt;
          &lt;/binding&gt;
  
          &lt;binding name="InquireSalesAccountProfileSoapHttpBinding"&gt;
            &lt;security mode="Transport" /&gt;
          &lt;/binding&gt;
  
          &lt;binding name="InquireUnifiedBillingReferenceDataSoapHttpBinding"&gt;
            &lt;security mode="Transport" /&gt;
          &lt;/binding&gt;
  
          &lt;binding name="ManageCustomLabelSoapHttpBinding"&gt;
            &lt;security mode="Transport" /&gt;
          &lt;/binding&gt;
  
          &lt;binding name="SendBillingReplyNotificationSoapHttpBinding"&gt;
            &lt;security mode="Transport" /&gt;
          &lt;/binding&gt;
  
          &lt;binding name="SubmitCustomerInquirySoapHttpBinding"&gt;
            &lt;security mode="Transport" /&gt;
          &lt;/binding&gt;
  
          &lt;binding name="SubmitSLACreditClaimSoapHttpBinding"&gt;
            &lt;security mode="Transport" /&gt;
          &lt;/binding&gt;
  
          &lt;binding name="UpdateBillingDisputeSoapHttpBinding"&gt;
            &lt;security mode="Transport" /&gt;
          &lt;/binding&gt;
  
          &lt;binding name="ValidateAddressServiceAvailabilitySoapHttpBinding"&gt;
            &lt;security mode="Transport" /&gt;
          &lt;/binding&gt;
  
        &lt;/basicHttpBinding&gt;
      &lt;/bindings&gt;
  
      &lt;client&gt;
        &lt;endpoint address="https://qa9-csiwwwi-tn.edc.cingular.net:19443/Services/com/cingular/csi/bdebill/CreateBillingDispute.jws"
            binding="basicHttpBinding" bindingConfiguration="CreateBillingDisputeSoapHttpBinding"
            contract="CreateBillingDisputePortType" name="CreateBillingDisputeSoapHttpPort" /&gt;
        &lt;endpoint address="https://qa9-csiwwwi-tn.edc.cingular.net:19443/Services/com/cingular/csi/bdebill/CreateBillingReport.jws"
            binding="basicHttpBinding" bindingConfiguration="CreateBillingReportSoapHttpBinding"
            contract="CreateBillingReportPortType" name="CreateBillingReportSoapHttpPort" /&gt;
        &lt;endpoint address="https://qa9-csiwwwi-tn.edc.cingular.net:19443/Services/com/cingular/csi/echo/Echo.jws"
            binding="basicHttpBinding" bindingConfiguration="EchoSoapHttpBinding"
            contract="EchoPortType" name="EchoSoapHttpPort" behaviorConfiguration="endpointCredentialBehavior" /&gt;
        &lt;endpoint address="https://qa9-csiwwwi-tn.edc.cingular.net:19443/Services/com/cingular/csi/bdebill/InquireBillingDisputeDetails.jws"
            binding="basicHttpBinding" bindingConfiguration="InquireBillingDisputeDetailsSoapHttpBinding"
            contract="InquireBillingDisputeDetailsPortType" name="InquireBillingDisputeDetailsSoapHttpPort" /&gt;
        &lt;endpoint address="https://qa9-csiwwwi-tn.edc.cingular.net:19443/Services/com/cingular/csi/bdebill/InquireBillingInvoiceDetails.jws"
            binding="basicHttpBinding" bindingConfiguration="InquireBillingInvoiceDetailsSoapHttpBinding"
            contract="InquireBillingInvoiceDetailsPortType" name="InquireBillingInvoiceDetailsSoapHttpPort" /&gt;
        &lt;endpoint address="https://qa9-csiwwwi-tn.edc.cingular.net:19443/Services/com/cingular/csi/bdebill/InquireBillingInvoiceSummary.jws"
            binding="basicHttpBinding" bindingConfiguration="InquireBillingInvoiceSummarySoapHttpBinding"
            contract="InquireBillingInvoiceSummaryPortType" name="InquireBillingInvoiceSummarySoapHttpPort" /&gt;
        &lt;endpoint address="https://qa9-csiwwwi-tn.edc.cingular.net:19443/Services/com/cingular/csi/iof/InquireEnterpriseOrderDetails.jws"
            binding="basicHttpBinding" bindingConfiguration="InquireEnterpriseOrderDetailsSoapHttpBinding"
            contract="InquireEnterpriseOrderDetailsPortType" name="InquireEnterpriseOrderDetailsSoapHttpPort" /&gt;
        &lt;endpoint address="https://qa9-csiwwwi-tn.edc.cingular.net:19443/Services/com/cingular/csi/sxp/InquireEnterpriseOrderList.jws"
            binding="basicHttpBinding" bindingConfiguration="InquireEnterpriseOrderListSoapHttpBinding"
            contract="InquireEnterpriseOrderListPortType" name="InquireEnterpriseOrderListSoapHttpPort" behaviorConfiguration="endpointCredentialBehavior" /&gt;
        &lt;endpoint address="https://qa9-csiwwwi-tn.edc.cingular.net:19443/Services/com/cingular/csi/sxp/InquireEnterpriseOrderStatus.jws"
            binding="basicHttpBinding" bindingConfiguration="InquireEnterpriseOrderStatusSoapHttpBinding"
            contract="InquireEnterpriseOrderStatusPortType" name="InquireEnterpriseOrderStatusSoapHttpPort" /&gt;
        &lt;endpoint address="https://qa9-csiwwwi-tn.edc.cingular.net:19443/Services/com/cingular/csi/pricing/InquireNetworkProductCatalog.jws"
            binding="basicHttpBinding" bindingConfiguration="InquireNetworkProductCatalogSoapHttpBinding"
            contract="InquireNetworkProductCatalogPortType" name="InquireNetworkProductCatalogSoapHttpPort" /&gt;
        &lt;endpoint address="https://qa9-csiwwwi-tn.edc.cingular.net:19443/Services/com/cingular/csi/pricing/InquireNetworkProductPriceQuote.jws"
            binding="basicHttpBinding" bindingConfiguration="InquireNetworkProductPriceQuoteSoapHttpBinding"
            contract="InquireNetworkProductPriceQuotePortType" name="InquireNetworkProductPriceQuoteSoapHttpPort" /&gt;
        &lt;endpoint address="https://qa9-csiwwwi-tn.edc.cingular.net:19443/Services/com/cingular/csi/pricing/InquireNetworkProductRateCard.jws"
            binding="basicHttpBinding" bindingConfiguration="InquireNetworkProductRateCardSoapHttpBinding"
            contract="InquireNetworkProductRateCardPortType" name="InquireNetworkProductRateCardSoapHttpPort" /&gt;
        &lt;endpoint address="https://qa9-csiwwwi-tn.edc.cingular.net:19443/Services/com/cingular/csi/isom/InquireSLACreditClaimStatus.jws"
            binding="basicHttpBinding" bindingConfiguration="InquireSLACreditClaimStatusSoapHttpBinding"
            contract="InquireSLACreditClaimStatusPortType" name="InquireSLACreditClaimStatusSoapHttpPort" /&gt;
        &lt;endpoint address="https://qa9-csiwwwi-tn.edc.cingular.net:19443/Services/com/cingular/csi/isom/InquireSLANetworkCreditClaimStatus.jws"
            binding="basicHttpBinding" bindingConfiguration="InquireSLANetworkCreditClaimStatusSoapHttpBinding"
            contract="InquireSLANetworkCreditClaimStatusPortType" name="InquireSLANetworkCreditClaimStatusSoapHttpPort" /&gt;
        &lt;endpoint address="https://qa9-csiwwwi-tn.edc.cingular.net:19443/Services/com/cingular/csi/bdebill/InquireSalesAccountProfile.jws"
            binding="basicHttpBinding" bindingConfiguration="InquireSalesAccountProfileSoapHttpBinding"
            contract="InquireSalesAccountProfilePortType" name="InquireSalesAccountProfileSoapHttpPort" /&gt;
        &lt;endpoint address="https://qa9-csiwwwi-tn.edc.cingular.net:19443/Services/com/cingular/csi/bdebill/InquireUnifiedBillingReferenceData.jws"
            binding="basicHttpBinding" bindingConfiguration="InquireUnifiedBillingReferenceDataSoapHttpBinding"
            contract="InquireUnifiedBillingReferenceDataPortType" name="InquireUnifiedBillingReferenceDataSoapHttpPort" /&gt;
        &lt;endpoint address="https://qa9-csiwwwi-tn.edc.cingular.net:19443/Services/com/cingular/csi/bdebill/ManageCustomLabel.jws"
            binding="basicHttpBinding" bindingConfiguration="ManageCustomLabelSoapHttpBinding"
            contract="ManageCustomLabelPortType" name="ManageCustomLabelSoapHttpPort" /&gt;
        &lt;endpoint address="https://qa9-csiwwwi-tn.edc.cingular.net:19443/Services/com/cingular/csi/bdebill/SendBillingReplyNotification.jws"
            binding="basicHttpBinding" bindingConfiguration="SendBillingReplyNotificationSoapHttpBinding"
            contract="SendBillingReplyNotificationPortType" name="SendBillingReplyNotificationSoapHttpPort" /&gt;
        &lt;endpoint address="https://qa9-csiwwwi-tn.edc.cingular.net:19443/Services/com/cingular/csi/bdebill/SubmitCustomerInquiry.jws"
            binding="basicHttpBinding" bindingConfiguration="SubmitCustomerInquirySoapHttpBinding"
            contract="SubmitCustomerInquiryPortType" name="SubmitCustomerInquirySoapHttpPort" /&gt;
        &lt;endpoint address="https://qa9-csiwwwi-tn.edc.cingular.net:19443/Services/com/cingular/csi/isom/SubmitSLACreditClaim.jws"
            binding="basicHttpBinding" bindingConfiguration="SubmitSLACreditClaimSoapHttpBinding"
            contract="SubmitSLACreditClaimPortType" name="SubmitSLACreditClaimSoapHttpPort" /&gt;
        &lt;endpoint address="https://qa9-csiwwwi-tn.edc.cingular.net:19443/Services/com/cingular/csi/bdebill/UpdateBillingDispute.jws"
            binding="basicHttpBinding" bindingConfiguration="UpdateBillingDisputeSoapHttpBinding"
            contract="UpdateBillingDisputePortType" name="UpdateBillingDisputeSoapHttpPort" /&gt;
        &lt;endpoint address="https://qa9-csiwwwi-tn.edc.cingular.net:19443/Services/com/cingular/csi/pricing/ValidateAddressServiceAvailability.jws"
            binding="basicHttpBinding" bindingConfiguration="ValidateAddressServiceAvailabilitySoapHttpBinding"
            contract="ValidateAddressServiceAvailabilityPortType" name="ValidateAddressServiceAvailabilitySoapHttpPort" /&gt;
      &lt;/client&gt;
    &lt;/system.serviceModel&gt;
  &lt;/configuration&gt;
  
  The entire stack trace:
  System.TypeInitializationException was unhandled
    HResult=-2146233036
    Message=The type initializer for 'System.ServiceModel.Diagnostics.TraceUtility' threw an exception.
    Source=System.ServiceModel
    TypeName=System.ServiceModel.Diagnostics.TraceUtility
    StackTrace:
         at System.ServiceModel.Diagnostics.TraceUtility.SetEtwProviderId()
         at System.ServiceModel.ChannelFactory..ctor()
         at System.ServiceModel.ChannelFactory`1..ctor(Type channelType)
         at System.ServiceModel.ChannelFactory`1..ctor(String endpointConfigurationName, EndpointAddress remoteAddress)
         at System.ServiceModel.ConfigurationEndpointTrait`1.CreateSimplexFactory()
         at System.ServiceModel.ConfigurationEndpointTrait`1.CreateChannelFactory()
         at System.ServiceModel.ClientBase`1.CreateChannelFactoryRef(EndpointTrait`1 endpointTrait)
         at System.ServiceModel.ClientBase`1.InitializeChannelFactoryRef()
         at System.ServiceModel.ClientBase`1..ctor(String endpointConfigurationName, String remoteAddress)
         at EchoPortTypeClient..ctor(String endpointConfigurationName, String remoteAddress) in c:\Clients\DRS\attws\attws\csi_v80_schema\CingularWirelessCSI.cs:line 22771
         at attws.Program.EchoTest() in c:\Clients\DRS\attws\attws\Program.cs:line 60
         at attws.Program.Main(String[] args) in c:\Clients\DRS\attws\attws\Program.cs:line 15
         at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
         at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
         at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
         at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
         at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
         at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
         at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
         at System.Threading.ThreadHelper.ThreadStart()
    InnerException: System.Configuration.ConfigurationErrorsException
         HResult=-2146232062
         Message=Configuration system failed to initialize
         Source=System.Configuration
         BareMessage=Configuration system failed to initialize
         Line=0
         StackTrace:
              at System.Configuration.ConfigurationManager.PrepareConfigSystem()
              at System.Configuration.ConfigurationManager.GetSection(String sectionName)
              at System.Configuration.PrivilegedConfigurationManager.GetSection(String sectionName)
              at System.Diagnostics.DiagnosticsConfiguration.GetConfigSection()
              at System.Diagnostics.DiagnosticsConfiguration.Initialize()
              at System.Diagnostics.DiagnosticsConfiguration.get_IndentSize()
              at System.Diagnostics.TraceInternal.InitializeSettings()
              at System.Diagnostics.TraceInternal.get_Listeners()
         InnerException: System.Configuration.ConfigurationErrorsException
              HResult=-2146232062
              Message=Unrecognized configuration section source. (C:\Clients\DRS\attws\attws\bin\Debug\attws.vshost.exe.Config line 15)
              Source=System.Configuration
              BareMessage=Unrecognized configuration section source.
              Filename=C:\Clients\DRS\attws\attws\bin\Debug\attws.vshost.exe.Config
              Line=15
              StackTrace:
                   at System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
                   at System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
                   at System.Configuration.BaseConfigurationRecord.ThrowIfInitErrors()
                   at System.Configuration.ClientConfigurationSystem.EnsureInit(String configKey)
              InnerException:
  </code></pre>