The type initializer for 'NHibernate.LoggerProvider' threw an exception [closed]
Asked Answered
L

5

8

I am trying to use the Common.Logging assembly to replace the default nHibernate Log4net logging.

I added a reference in my project to:
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"/>

My ulitmate goal is to replace the Log4net logging with the Enterprise Library 5.0, but I'm just taking it one step at a time at the moment.

When I run my app now 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 anything that I'm missing to use the Common.Logging with nHibernate? I've tried following the instructions I've found on the web but it's not working and I can't find a solution :(

I'm using NHibernate v3.2.0.4000.

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

Langur answered 24/11, 2011 at 18:9 Comment(2)
I wish this question was answered. This is the same exact problem I am havingAscospore
It is answered, just he didn't mark it. One of the throwaway accounts, just made to ask one question. Basically, the config string is copied from a tutorial, and it has a typo. "..., Hibernate.Logging.". It should be NHibernate.LoggingOestrone
S
8

switch Hibernate.Logging.CommonLogging with NHibernate.Logging.CommonLogging

Soberminded answered 25/11, 2011 at 13:39 Comment(1)
I think we followed the same web how-to, and ended up copying his typo into our own config.Oestrone
G
3

try installing the NHibernate.Logging package from NuGet (or referencing the library, if you don't use NuGet). Worked for me.

Cheers.

Governess answered 26/1, 2012 at 4:21 Comment(0)
E
2

If you are running your solution on windows server 2008, and using NHibernate 3.0+, make sure you have .Net 3.5 installed and that aspnet_regiis has been executed for .net framework (or frameworkx64) 2.0. Also if it is a website, make sure it is running on classic .net app pool and not the default app pool.

NHibernate 3.0+ needs .net 3.0 and above.

Etherealize answered 14/12, 2012 at 6:4 Comment(0)
T
1

Short Version

Check if your project's Assembly Name matches the value in the nhibernate-logger key in your web.config

Long Version

This is an old question, but I came across it when I had the same error. In my case the problem was caused because I renamed the project where the NLogFactory was located and changed the web.config to reflect that, but forgot to change the project's assembly name.

That is, I renamed my project from CDP.Core to ARR.Code, went into 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 forgot to go into the project properties, "Application" tab, and change "Assembly name" to the new name.

Tartrate answered 11/8, 2015 at 17:56 Comment(0)
A
0

I'm continuing to get this exception with my own DLL that implements logging to NLog. My versions: FluentNHibernate 3.3.0 and NHibernate 5.5.3.

Same error when using app.config with either an implementation of ILoggerFactory or INHibernateLoggerFactory

Managed to get it working by adding the following in code, just before building the configuration.

    //LoggerProvider.SetLoggersFactory(new NLogLoggerFactory()); // ILoggerFactory
    NHibernateLogger.SetLoggersFactory(new NLogLoggerFactory()); // INHibernateLoggerFactory

A

Adige answered 25/4 at 9:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.