Eric B Eric B - 13 days ago 10
C# Question

Getting TypeInitializationException after making unrelated change in app.config

I'm working on a c# project and I've been seeing an odd behavior. I started my IDE and made a few changes in the XAML of my wpf project, ran it, and everything worked fine. But then I went and changed the log size in my app.config and went to run it again and it gave me the below error:

System.TypeInitializationException was unhandled
Message: An unhandled exception of type 'System.TypeInitializationException' occurred in PresentationFramework.dll
Additional information: The type initializer for 'System.Windows.Application' threw an exception.


Everything I've been able to find while searching online for this error is people who have had their app config in the wrong order (for instance the startup block above the config section block) but that doesn't seem to be the case for mine. Below is my app config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
</providers>
</entityFramework>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="Npgsql" publicKeyToken="5d8b90d52f46fda7" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-3.1.0.0" newVersion="3.1.0.0" />
</dependentAssembly>
<dependentAssembly>
<publisherPolicy apply="no" />
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
<bindingRedirect oldVersion="4.121.0.0 - 4.65535.65535.65535" newVersion="4.121.2.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<system.data>
<DbProviderFactories>
<remove invariant="Oracle.ManagedDataAccess.Client" />
<add name="ODP.NET, Managed Driver" invariant="Oracle.ManagedDataAccess.Client" description="Oracle Data Provider for .NET, Managed Driver" type="Oracle.ManagedDataAccess.Client.OracleClientFactory, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342" />
</DbProviderFactories>
</system.data>
<log4net>
<root>
<level value="INFO"/>
<appender-ref ref="FileAppender"/>
<appender-ref ref="RollingFileAppender"/>
</root>
<appender name="FileAppender" type="log4net.Appender.FileAppender">
<file value="logs/client.log" />
<appendToFile value="false" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="logs/full.log" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="10" />
<maximumFileSize value="20MB" />
<staticLogFileName value="true" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%date [%thread] %-5level %logger [%property{NDC}] - %message%newline" />
</layout>
</appender>
</log4net>
<oracle.manageddataaccess.client>
<version number="*">
<dataSources>
<dataSource alias="ProdCon" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=prodip)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=prod))) " />
<dataSource alias="TestCon" descriptor="(DESCRIPTION=(ADDRESS=(PROTOCOL=tcp)(HOST=testip)(PORT=1521))(CONNECT_DATA=(SID=test))) " />
</dataSources>
</version>
</oracle.manageddataaccess.client>
</configuration>


The only thing I did was change the
<maximumFileSize value="20MB" />
from 20MB to 25MB. I changed it back and it's still throwing the above error.

Any direction in fixing this issue or where to go for more information (this exception seems a bit light on any kind of explanation, and breaks before it hits any of my logging) would be appreciated.

EDIT: I was just attempting to run the project again and received a new error message that I've never seen before:

VS error

Answer

There's no log4net configuration section defined in configSections at the top of your config file.

 <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
Comments