A type initializer for "NHibernate.LoggerProvider" threw an exception

I am trying to use the Common.Logging assembly to replace the default nHibernate log4net log.

I added a link to my project:
Common.Logging.dll v2.0
NHibernate.Logging.CommonLogging.dll v1.2.0.4000

and then added the following to my Web.config:

<add key="nhibernate-logger" value="NHibernate.Logging.CommonLogging.CommonLoggingLoggerFactory, Hibernate.Logging.CommonLogging"/> 

The purpose of my ulitmate is to replace Log4net with Enterprise Library 5.0, but I'm just doing it step by step for now.

When I run my application, I get the following exception:

 The type initializer for 'NHibernate.Cfg.Configuration' threw an exception. => The type initializer for 'NHibernate.LoggerProvider' threw an exception. => The type initializer for 'NHibernate.LoggerProvider' threw an exception. => Unable to instantiate: => Value cannot be null.\r\nParameter name: type at NHibernate.LoggerProvider.LoggerFor(Type type) at NHibernate.Cfg.Configuration..cctor() 

Is there something I am missing to use Common.Logging with nHibernate? I tried to follow the instructions that I found on the Internet, but it does not work, and I can not find a solution :(

I am using NHibernate v3.2.0.4000.

PS. This is my first post on this site, so sorry if the formatting is wrong, I will be glady to accept constructive criticism: o)

+8
nhibernate common.logging
source share
4 answers

toggle Hibernate.Logging.CommonLogging with N Hibernate.Logging.CommonLogging

+8
source share

try installing the NHibernate.Logging package from NuGet (or a link to the library if you are not using NuGet). Worked for me.

Greetings.

+2
source share

If you use the solution on a Windows 2008 server and use NHibernate 3.0+, make sure that you have .Net 3.5 installed and that aspnet_regiis made for the .NET Framework (or frameworkx64) 2.0. Also, if this is a website, make sure that it runs in the classic .net application pool and not in the default application pool.

NHibernate 3.0+ requires .net 3.0 and higher.

+2
source share

Short version

Check if your project assembly name matches the value in nhibernate-logger in web.config

Long version

This is an old question, but I ran into it when I had the same error. In my case, the problem was caused by the fact that I renamed the project where NLogFactory was NLogFactory and changed web.config to reflect this, but forgot to change the assembly name of the project.

That is, I renamed my project from CDP.Core to ARR.Code , went to my web.config to change

 <add key="nhibernate-logger" value="CDP.Core.DBContext.Framework.NLogFactory, CDP.Core" /> 

To:

 <add key="nhibernate-logger" value="ARR.Core.DBContext.Framework.NLogFactory, ARR.Core" /> 

But they forgot to enter the project properties, the "Application" tab and change the "Assembly Name" to a new name.

0
source share

All Articles