Click here to Skip to main content
15,894,291 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I got the following error

The type initializer for 'System.Windows.Application' threw an exception


when I've the following content in app.config file. This is a WPF application.

XML
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
	<log4net>
		<appender name="RollingFileAppenderV1" type="log4net.Appender.RollingFileAppender">
			<file type="log4net.Util.PatternString" value="xxxzzzlog.txt"/>
			<appendToFile value="true"/>
			<rollingStyle value="Size"/>
			<maxSizeRollBackups value="50"/>
			<maximumFileSize value="100KB"/>
			<staticLogFileName value="true"/>
			<countDirection value="1"/>
			<layout type="log4net.Layout.PatternLayout">
				<param name="ConversionPattern" value="[%d{yyyy-MM-dd hh:mm:ss}] - [%-5p] – %m%n"/>
			</layout>
		</appender>
		<root>
			<level value="ALL"/>
			<appender-ref ref="RollingFileAppenderV1"/>
		</root>
	</log4net>
	<startup>
		<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
	</startup>
</configuration>


Still I couldn't find what's wrong with this config file. Without the log4net configuration it works fine. Any comments really appreciate.
Posted

1 solution

I Found the solutions, I've miss the configuration for log4net. Following need to be in the app.config just before the log4net tag.

XML
<configsections>
	<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,Log4net" />
</configsections>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900