views:

575

answers:

2

Hi Guys,

I was having issues in log4net when i updated my solutions to .net 4.0 , and then i downloaded the source of it and built log4net and targeted it to .net 4.0 and used it in my projects.

initially when i referred log4net that is targeted to run time 2.0 it complied and run the application but log did not work.

now when i run my project with log4net targeted to .net 4.0 i get the error " The type initializer for 'Log4NetTest.TestLog' threw an exception."

Any Idea how to solve this

Edit: This is the Inner Exception: InnerException: System.TypeLoadException Message=Inheritance security rules violated while overriding member: 'log4net.Util.ReadOnlyPropertiesDictionary.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext)'. Security accessibility of the overriding method must match the security accessibility of the method being overriden. Source=log4net TypeName=log4net.Util.ReadOnlyPropertiesDictionary.GetObjectData(System.Runtime.Serialization.SerializationInfo, System.Runtime.Serialization.StreamingContext) StackTrace: at log4net.Repository.Hierarchy.Hierarchy..ctor(ILoggerFactory loggerFactory) at log4net.Repository.Hierarchy.Hierarchy..ctor() in C:\src\Repository\Hierarchy\Hierarchy.cs:line 150 InnerException:

A: 

This worked for me:

In the log4net source code, add a [SecurityCritical] attribute to the Util.ReadOnlyPropertiesDictionary.GetObjectData method and build.

There might be some other things you'll need to do to get it to build for the 4.0 framework.

See this post:

http://stackoverflow.com/questions/1924814/weird-override-problem-with-fluent-nhibernate-and-net-4

Chris Ellingsworth
+1  A: 

Hi folks,

A solution can be found on http://tseonet.blogspot.com/2010/07/making-log4net-run-on-net-40.html.

Tjeez