简体   繁体   中英

nHibernate Log4Net logging exception

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.

您需要在log4net源中的Util.ReadOnlyPropertiesDictionary.GetObjectData中添加SecurityCritical属性,详见https://stackoverflow.com/a/2977020/43846

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM