Eric B Eric B - 1 year ago 154
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"?>
<!-- For more information on Entity Framework configuration, visit -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<section name="oracle.manageddataaccess.client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=, Culture=neutral, PublicKeyToken=89b483f429c47342" />
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity name="Npgsql" publicKeyToken="5d8b90d52f46fda7" culture="neutral" />
<bindingRedirect oldVersion="" newVersion="" />
<publisherPolicy apply="no" />
<assemblyIdentity name="Oracle.ManagedDataAccess" publicKeyToken="89b483f429c47342" culture="neutral" />
<bindingRedirect oldVersion=" - 4.65535.65535.65535" newVersion="" />
<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=, Culture=neutral, PublicKeyToken=89b483f429c47342" />
<level value="INFO"/>
<appender-ref ref="FileAppender"/>
<appender-ref ref="RollingFileAppender"/>
<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" />
<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" />
<version number="*">
<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))) " />

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 Source

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

 <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download