Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

log4net and .net Framework 4.0

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
like image 630
Aneef Avatar asked Dec 12 '25 07:12

Aneef


1 Answers

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

Just compiled the source for target framework 4.0 (not client). Source code of version 1.2.11 already contains this attribute, but be sure to use 'NET_4_0' as a compiler argument. Otherwise, this attribute will not be added.

like image 61
Björn Avatar answered Dec 15 '25 23:12

Björn



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!