Skip to content

Cannot create configuration due to log4net loading failure #1836

@JonasBRasmussen

Description

@JonasBRasmussen

I'm trying to upgrade NH from 4.0.0 til 5.1.3. I have installed the proper Nuget packages and have not yet changed any existing code. This is the first (and right now, only) line of NHibernate-related code:

var config = new NHibernate.Cfg.Configuration();

After this, I plan to do different things to complete the configuration. However, the code fails at this line and I am unable to do any configuration.

I cloned the NH repo so I could debug the problem, and I cannot get past the line

properties = Environment.Properties;

in the Reset() method of the NHibernate.Cfg.Configuration class.

All projects in my solution target .NET 4.6.1. A thing to note is that my web projects are SharePoint (2016) projects, and the assemblies are therefore deployed to the GAC. I have confirmed that all the assemblies have been deployed correctly and that there are no versioning issues (only one version of each NHibernate-related assembly is deployed to the GAC). And just to be clear, everything worked without issue on the same setup with NH 4.0.0 (if I uninstall 5.1.3 and go back to 4.0.0, then everything works just fine again).

I have spent the last couple of days on this upgrade and I am getting no closer to a solution. I hope you can help me out.

The complete stack trace for the exception is:

System.TypeInitializationException: The type initializer for 'NHibernate.Cfg.Environment' threw an exception.
---> System.TypeInitializationException: The type initializer for 'NHibernate.NHibernateLogger' threw an exception.
---> NHibernate.InstantiationException: Unable to instantiate: NHibernate.Log4NetLoggerFactoryNHibernate.Log4NetLoggerFactory
---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
---> System.TypeInitializationException: The type initializer for 'NHibernate.Log4NetLoggerFactory' threw an exception.
---> System.NullReferenceException: Object reference not set to an instance of an object.
   at NHibernate.Log4NetLoggerFactory.GetGetLoggerByNameMethodCall()
   at NHibernate.Log4NetLoggerFactory..cctor()
   --- End of inner exception stack trace ---
   at NHibernate.Log4NetLoggerFactory..ctor()
   --- End of inner exception stack trace ---
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at NHibernate.NHibernateLogger.GetLoggerFactory(String nhibernateLoggerClass)
   --- End of inner exception stack trace ---
   at NHibernate.NHibernateLogger.GetLoggerFactory(String nhibernateLoggerClass)
   at NHibernate.NHibernateLogger..cctor()
   --- End of inner exception stack trace ---
   at NHibernate.NHibernateLogger.For(Type type)
   at NHibernate.Cfg.Environment..cctor()
   --- End of inner exception stack trace ---
   at NHibernate.Cfg.Configuration.Reset()
   at MyCompany.MyProject.CreateNHibernateConfiguration()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions