TypeInitializationException when trying to config log4net
<p>I have a VS2015 solution that includes a service layer, which exposes a set of WCF services, and a WPF client that consumes them. I have log4net configured and working fine in the service layer</p>

<p>I now want to use log4net in the client, so added the log4net NuGet package, and copied the  node from the service layer's config file into the App.config file for the client. The full file looks like this...</p>

<pre><code>&lt;?xml version="1.0"
      encoding="utf-8"?&gt;

&lt;configuration&gt;
  &lt;startup&gt;
    &lt;supportedRuntime version="v4.0"
                      sku=".NETFramework,Version=v4.5.2" /&gt;
  &lt;/startup&gt;

  &lt;log4net&gt;
    &lt;appender name="RollingFileAppender"
              type="log4net.Appender.RollingFileAppender"&gt;
      &lt;param name="File"
             value="PhysioDiary.log" /&gt;
      &lt;appendToFile value="true" /&gt;
      &lt;rollingStyle value="Size" /&gt;
      &lt;maxSizeRollBackups value="2" /&gt;
      &lt;maximumFileSize value="1MB" /&gt;
      &lt;staticLogFileName value="true" /&gt;
      &lt;layout type="log4net.Layout.PatternLayout"&gt;
        &lt;conversionPattern value="%date [%thread] %-7level %logger - %message%newline%exception" /&gt;
      &lt;/layout&gt;
    &lt;/appender&gt;
    &lt;root&gt;
      &lt;level value="DEBUG" /&gt;
      &lt;appender-ref ref="RollingFileAppender" /&gt;
    &lt;/root&gt;
  &lt;/log4net&gt;

  &lt;system.serviceModel&gt;
    &lt;behaviors&gt;
      &lt;endpointBehaviors&gt;
        &lt;behavior name="LargeMessageBehavior"&gt;
          &lt;dataContractSerializer maxItemsInObjectGraph="2147483647" /&gt;
        &lt;/behavior&gt;
      &lt;/endpointBehaviors&gt;
    &lt;/behaviors&gt;

    &lt;bindings&gt;
      &lt;customBinding&gt;
        &lt;binding name="CustomBindingDefault"
                 closeTimeout="00:59:00"
                 openTimeout="00:59:00"
                 receiveTimeout="00:59:00"
                 sendTimeout="00:59:00"&gt;
          &lt;binaryMessageEncoding&gt;
            &lt;readerQuotas maxDepth="6400"
                          maxStringContentLength="100000000"
                          maxArrayLength="2147483647" /&gt;
          &lt;/binaryMessageEncoding&gt;
          &lt;httpTransport maxBufferPoolSize="2147483647"
                         maxReceivedMessageSize="2147483647"
                         bypassProxyOnLocal="true"
                         keepAliveEnabled="false"
                         maxBufferSize="2147483647"&gt;
            &lt;extendedProtectionPolicy policyEnforcement="Never" /&gt;
          &lt;/httpTransport&gt;
        &lt;/binding&gt;
      &lt;/customBinding&gt;
    &lt;/bindings&gt;

    &lt;client&gt;
      &lt;endpoint address="http://localhost:5448/AppointmentsService.svc"
                behaviorConfiguration="LargeMessageBehavior"
                binding="customBinding"
                bindingConfiguration="CustomBindingDefault"
                contract="AppointmentsServiceReference.AppointmentsService"
                name="CustomBinding_AppointmentsService" /&gt;
      &lt;!-- Other WCF services here, snipped for clarity --&gt;
    &lt;/client&gt;
  &lt;/system.serviceModel&gt;
&lt;/configuration&gt;
</code></pre>

<p>Even before using log4net anywhere, if I try to run the client now, I get an exception...</p>

<blockquote>
  <p>An unhandled exception of type 'System.TypeInitializationException'
  occurred in PresentationFramework.dll</p>
  
  <p>Additional information: The type initializer for
  'System.Windows.Application' threw an exception.</p>
</blockquote>

<p>...and the client won't start. It doesn't break on any code, so I can't see a stack trace, nor see if there is an inner exception.</p>

<p>If I comment out the contents of the  node, but leave the empty node there, I still get the exception, so it doesn't seem to be the contents of the node, nor the RollingFileAppender that are the problem.</p>

<p>I've checked the references, and both projects have log4net v2.0.5 referenced, and neither have any other log4net references. Both projects use Ninject, although I'm not sure that's relevant as I'm not injecting log4net in either project (yet, that's the next step).</p>

<p>It's not the problem reported in <a href="https://stackoverflow.com/questions/22596406/exception-when-adding-log4net-config">this SO question</a>, as my config file doesn't have appSettings nor configSections. Also, the startup node has always been the first in the file, and this has never caused a problem. I did try moving it to the end, but it didn't help.</p>

<p>Anyone any ideas why it crashes when I try to add log4net to the WPF client?</p>