Venil Aravazhi
Venil Aravazhi

Reputation: 299

The type initializer for 'System.ServiceModel.Diagnostics.TraceUtility' threw an exception

I have developed a console application using C#, to access another API and pull relevant data. It works fine, when I have checked with a small amount of data inputs. While I am doing load testing with huge amount of datas, it throws an exception.

The Exception is:

The type initializer for 'System.ServiceModel.Diagnostics.TraceUtility' threw an exception.

My app.config:

<?xml version="1.0"?>
<configuration>
    <commonBehaviors>
        <serviceBehaviors>
            <serviceTimeouts transactionTimeout="01:55:00"/>
        </serviceBehaviors>
    </commonBehaviors>

    <bindings>
        <customBinding>
            <binding name="EloquaService"
                     closeTimeout="00:55:00"
                     openTimeout="00:55:00"
                     receiveTimeout="00:55:00"
                     sendTimeout="01:55:00">
                <security defaultAlgorithmSuite="Default"
                          authenticationMode="UserNameOverTransport"
                          requireDerivedKeys="true"
                          securityHeaderLayout="Strict"
                          includeTimestamp="true"
                          keyEntropyMode="CombinedEntropy"
                          messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">

                    <localClientSettings cacheCookies="true"
                                         detectReplays="false"
                                         replayCacheSize="900000"
                                         maxClockSkew="00:05:00"
                                         maxCookieCachingTime="Infinite"
                                         replayWindow="00:05:00"
                                         sessionKeyRenewalInterval="10:00:00"
                                         sessionKeyRolloverInterval="00:05:00"
                                         reconnectTransportOnFailure="true"
                                         timestampValidityDuration="00:05:00"
                                         cookieRenewalThresholdPercentage="60"/>
                    <localServiceSettings detectReplays="false"
                                          issuedCookieLifetime="10:00:00"
                                          maxStatefulNegotiations="128"
                                          replayCacheSize="900000"
                                          maxClockSkew="00:05:00"
                                          negotiationTimeout="00:01:00"
                                          replayWindow="00:05:00"
                                          inactivityTimeout="00:02:00"
                                          sessionKeyRenewalInterval="15:00:00"
                                          sessionKeyRolloverInterval="00:05:00"
                                          reconnectTransportOnFailure="true"
                                          maxPendingSessions="128"
                                          maxCachedCookies="1000"
                                          timestampValidityDuration="00:05:00"/>
                    <secureConversationBootstrap/>
                </security>
                <textMessageEncoding maxReadPoolSize="64"
                                     maxWritePoolSize="16"
                                     messageVersion="Soap11"
                                     writeEncoding="utf-8">
                    <readerQuotas maxDepth="32"
                                  maxStringContentLength="8192"
                                  maxArrayLength="16384"
                                  maxBytesPerRead="4096"
                                  maxNameTableCharCount="16384"/>
                </textMessageEncoding>
                <httpsTransport manualAddressing="false"
                                maxBufferPoolSize="524288"
                                maxReceivedMessageSize="65536"
                                allowCookies="false"
                                authenticationScheme="Anonymous"
                                bypassProxyOnLocal="false"
                                decompressionEnabled="true"
                                hostNameComparisonMode="StrongWildcard"
                                keepAliveEnabled="true"
                                maxBufferSize="65536"
                                proxyAuthenticationScheme="Anonymous"
                                realm=""
                                transferMode="Buffered"
                                unsafeConnectionNtlmAuthentication="false"
                                useDefaultWebProxy="true"
                                requireClientCertificate="false"/>
            </binding>
            <binding name="EmailServiceEndpoint"
                     closeTimeout="00:55:00"
                     openTimeout="00:55:00"
                     receiveTimeout="00:55:00"
                     sendTimeout="01:55:00">
                <security defaultAlgorithmSuite="Default"
                          authenticationMode="UserNameOverTransport"
                          requireDerivedKeys="true"
                          securityHeaderLayout="Strict"
                          includeTimestamp="true"
                          keyEntropyMode="CombinedEntropy"
                          messageSecurityVersion="WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityPolicy11BasicSecurityProfile10">
                    <localClientSettings cacheCookies="true"
                                         detectReplays="false"
                                         replayCacheSize="900000"
                                         maxClockSkew="00:05:00"
                                         maxCookieCachingTime="Infinite"
                                         replayWindow="00:05:00"
                                         sessionKeyRenewalInterval="10:00:00"
                                         sessionKeyRolloverInterval="00:05:00"
                                         reconnectTransportOnFailure="true"
                                         timestampValidityDuration="00:05:00"
                                         cookieRenewalThresholdPercentage="60"/>
                    <localServiceSettings detectReplays="false"
                                          issuedCookieLifetime="10:00:00"
                                          maxStatefulNegotiations="128"
                                          replayCacheSize="900000"
                                          maxClockSkew="00:05:00"
                                          negotiationTimeout="00:01:00"
                                          replayWindow="00:05:00"
                                          inactivityTimeout="00:02:00"
                                          sessionKeyRenewalInterval="15:00:00"
                                          sessionKeyRolloverInterval="00:05:00"
                                          reconnectTransportOnFailure="true"
                                          maxPendingSessions="128"
                                          maxCachedCookies="1000"
                                          timestampValidityDuration="00:05:00"/>
                    <secureConversationBootstrap/>
                </security>
                <textMessageEncoding maxReadPoolSize="64"
                                     maxWritePoolSize="16"
                                     messageVersion="Soap11"
                                     writeEncoding="utf-8">
                    <readerQuotas maxDepth="32"
                                  maxStringContentLength="8192"
                                  maxArrayLength="16384"
                                  maxBytesPerRead="4096"
                                  maxNameTableCharCount="16384"/>
                </textMessageEncoding>
                <httpsTransport manualAddressing="false"
                                maxBufferPoolSize="524288"
                                maxReceivedMessageSize="65536"
                                allowCookies="false"
                                authenticationScheme="Anonymous"
                                bypassProxyOnLocal="false"
                                decompressionEnabled="true"
                                hostNameComparisonMode="StrongWildcard"
                                keepAliveEnabled="true"
                                maxBufferSize="65536"
                                proxyAuthenticationScheme="Anonymous"
                                realm=""
                                transferMode="Buffered"
                                unsafeConnectionNtlmAuthentication="false"
                                useDefaultWebProxy="true"
                                requireClientCertificate="false"/>
            </binding>
        </customBinding>
    </bindings>
    <client>
        <endpoint address="https://secure.eloqua.com/API/1.2/service.svc"
                  binding="customBinding"
                  bindingConfiguration="EloquaService"
                  contract="EloquaService.EloquaService"
                  name="EloquaService"/>
        <endpoint address="https://secure.eloqua.com/API/1.2/ExternalActionService.svc"
                  binding="customBinding"
                  bindingConfiguration="EmailServiceEndpoint"
                  contract="EloquaProgramService.ExternalActionService"
                  name="EmailServiceEndpoint"/>
    </client>

    </system.serviceModel>

    <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
    </startup>
</configuration>

How do I solve this problem?

Upvotes: 1

Views: 11957

Answers (3)

spicet
spicet

Reputation: 561

I had similar exception and problem was

1) having two config files and had similar settings (web.config in Web layer / app.config in Service Layer-we were calling external service)

2) invalid section in web.config (log4net config section)

Visual studio did not show any error for no#2 as its looks valid section for VS but at run time it was throwing error. Removed app.config in Service layer and it resolved issue.

Upvotes: 0

Venil Aravazhi
Venil Aravazhi

Reputation: 299

The issue has been overcome. Probably I was having two app.config files. One is from the service reference and another one from my application. Both were having the same code. I just removed the below code from my appl.config which is placed in my application. Now it is not throwing the above exception.

<commonBehaviors>
    <serviceBehaviors>
        <serviceTimeouts transactionTimeout="01:55:00"/>
    </serviceBehaviors>
</commonBehaviors>

Upvotes: 1

Mridul
Mridul

Reputation: 757

This happened to me just now. I thought of sharing, even though it is very silly.

Here is what I did

I added reference to WCF service in a console application.

I added a key-value pair value in config without it being inside appSettings section in the config. In my haste to test the service I ran my console application and got the exact same error.

On going into the error details, I figured it was because of invalid config entries in my config.

Once I added the key value pair inside appSettings section, it worked. I know it's silly, but still it happened to me. :).

Upvotes: 0

Related Questions