0

I have a project, fully setup and tested successfully with nHibernate that I am trying to run in debug mode with Visual Studio 2010. Running the project prior to setting up log4net obviously runs fine, but adding the reference to the log4net assembly, the appropriate lines int web\Global.Asax file, and the configuration parameters in the web.config file result in the following error

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.

at line

Configuration configuration = new Configuration().Configure();

in the following block of code

public static ISessionFactory SessionFactory;
    public static ISession OpenSession()
    {
        if (SessionFactory == null) //not threadsafe
        { //SessionFactories are expensive, create only once
            Configuration configuration = new Configuration().Configure();
            configuration.AddAssembly(Assembly.GetCallingAssembly());
            SessionFactory = configuration.BuildSessionFactory();
        }
        return SessionFactory.OpenSession();
    }

I am explicity following this guide: Configure Log4Net for use with NHibernate from the nHibernate project.

sammarcow
  • 2,736
  • 2
  • 28
  • 56
  • Are you using .Net 4? http://stackoverflow.com/questions/3055792/inheritance-security-rules-violated-while-overriding-member-securityruleset-le might apply. – stuartd Nov 29 '12 at 16:12
  • I am using .Net 4 Trying to test a resolution, trying to enable Code Analysis With Security Set with [Enable Code Analysis](http://msdn.microsoft.com/en-us/library/e05a02t4(v=vs.80).aspx) but there is no "Website" when selecting my Web Project on the menu bar. Do you know how to access this setting? – sammarcow Nov 29 '12 at 16:23
  • I'm not sure. Are you using the .Net 4 build of log4net? Which version? – stuartd Nov 29 '12 at 16:34
  • I built the application by loading the solution file lof4net.vs2010 in the ..\src file within the log4net application. There are not .net version specific builds included with the solution. – sammarcow Nov 29 '12 at 16:49
  • You may need to add the attributes to the log4net source code as detailed at http://stackoverflow.com/a/2977020/43846 – stuartd Nov 29 '12 at 17:00
  • Building .log4net with the Attribute `[SecurityCritical]` in **Util.ReadOnlyPropertiesDictionary.GetObjectData** avoided the runtime error, please post this as a solution – sammarcow Nov 29 '12 at 17:18

2 Answers2

2

You need to add the SecurityCritical Attribute in Util.ReadOnlyPropertiesDictionary.GetObjectData in the log4net source as detailed at https://stackoverflow.com/a/2977020/43846

Community
  • 1
  • 1
stuartd
  • 70,509
  • 14
  • 132
  • 163
0

You should download version 1.2.11 of log4net. It includes an assembly targetting .NET 4.0 which contains many more fixed than just that one attribute.

cremor
  • 6,669
  • 1
  • 29
  • 72