NHibernateProfiler.Initialize() throws NullReferenceException

202 views
Skip to first unread message

Filip Filipov

unread,
Jun 7, 2019, 2:08:54 PM6/7/19
to nhprof
With the latest NuGet package and NHibernate versions >= 5.1.0 calling NHibernateProfiler.Initialize() fails

[NullReferenceException: Object reference not set to an instance of an object.]
   HibernatingRhinos.Profiler.Appender.NHibernate3Logger.WrapNHibernateLogger.GetOriginalLoggerFactory() +60
   HibernatingRhinos.Profiler.Appender.NHibernate3Logger.WrapNHibernateLogger.Initialize() +10

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
   System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +260
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +142
   HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.RegisterAppenderUsingNHibernateLogger() +493
   HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.StartNHibernateProfiling() +168
   HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize(NHibernateAppenderConfiguration configuration) +176

Oren Eini (Ayende Rahien)

unread,
Jun 7, 2019, 2:16:06 PM6/7/19
to nhprof
Can you send us a sample project?

--
You received this message because you are subscribed to the Google Groups "nhprof" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhprof+un...@googlegroups.com.
To post to this group, send email to nhp...@googlegroups.com.
Visit this group at https://groups.google.com/group/nhprof.
To view this discussion on the web visit https://groups.google.com/d/msgid/nhprof/257f5439-efd0-471d-9f17-92b9116fcbc5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Oren Eini
CEO   /   Hibernating Rhinos LTD
Skype:  ayenderahien
Support:  sup...@ravendb.net

Filip Filipov

unread,
Jun 10, 2019, 3:42:44 AM6/10/19
to nhprof
I looked at the code of GetOriginalLoggerFactory() with ReSharper and it's pretty obvious what the problem is

private static ILoggerFactory GetOriginalLoggerFactory()
{
// Get original logger factory from: LoggerProvider.instance.loggerFactory
var loggerProvider = typeof (LoggerProvider);
var instanceField = loggerProvider.GetField("instance", BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.GetField);
var instance = (LoggerProvider)instanceField.GetValue(null);
var loggerFactoryField = loggerProvider.GetField("loggerFactory", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField);
var loggerFactory = (ILoggerFactory)loggerFactoryField.GetValue(instance);
return loggerFactory ?? new NoLoggingLoggerFactory();
}

The LoggerProvider no longer has the "instance" and "loggerFactory" fields as of NHibernate 5.1. In fact the whole class has been marked obsolete, so this might affect other methods beyond GetOriginalLoggerFactory().

петък, 7 юни 2019 г., 21:16:06 UTC+3, Ayende Rahien написа:
Can you send us a sample project?

On Fri, Jun 7, 2019 at 9:08 PM Filip Filipov <filiprf...@gmail.com> wrote:
With the latest NuGet package and NHibernate versions >= 5.1.0 calling NHibernateProfiler.Initialize() fails

[NullReferenceException: Object reference not set to an instance of an object.]
   HibernatingRhinos.Profiler.Appender.NHibernate3Logger.WrapNHibernateLogger.GetOriginalLoggerFactory() +60
   HibernatingRhinos.Profiler.Appender.NHibernate3Logger.WrapNHibernateLogger.Initialize() +10

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
   System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +260
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +142
   HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.RegisterAppenderUsingNHibernateLogger() +493
   HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.StartNHibernateProfiling() +168
   HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize(NHibernateAppenderConfiguration configuration) +176

--
You received this message because you are subscribed to the Google Groups "nhprof" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nhp...@googlegroups.com.

To post to this group, send email to nhp...@googlegroups.com.
Visit this group at https://groups.google.com/group/nhprof.
To view this discussion on the web visit https://groups.google.com/d/msgid/nhprof/257f5439-efd0-471d-9f17-92b9116fcbc5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Oren Eini (Ayende Rahien)

unread,
Jun 13, 2019, 12:04:11 PM6/13/19
to nhprof
Thanks, we'll look at that. Hopefully will be fixed by next week 

To unsubscribe from this group and stop receiving emails from it, send an email to nhprof+un...@googlegroups.com.

To post to this group, send email to nhp...@googlegroups.com.
Visit this group at https://groups.google.com/group/nhprof.

For more options, visit https://groups.google.com/d/optout.

Oren Eini (Ayende Rahien)

unread,
Jul 1, 2019, 3:39:36 AM7/1/19
to nhprof
Hi,
Just to let you know, we expect to fix this issue mid next week

On Mon, Jun 10, 2019 at 10:42 AM Filip Filipov <filiprf...@gmail.com> wrote:
To unsubscribe from this group and stop receiving emails from it, send an email to nhprof+un...@googlegroups.com.

To post to this group, send email to nhp...@googlegroups.com.
Visit this group at https://groups.google.com/group/nhprof.

For more options, visit https://groups.google.com/d/optout.

Oren Eini (Ayende Rahien)

unread,
Jul 7, 2019, 9:53:17 AM7/7/19
to nhprof
Okay, I looked more deeply into that, and it seems very strange. We are handling this properly, it seems. It is possible that you have multiple NHibernate assemblies?

What is the output of this code?

var nhibernateAssembly = GetAssembly("NHibernate");
var isNHibernate5 = nhibernateAssembly.GetType("NHibernate.INHibernateLogger") != null;


private static Assembly GetAssembly(string assemblyName)
{
var assembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(asm => asm.GetName().Name == assemblyName);
if (assembly != null)
return assembly;

var asmName = Assembly.GetCallingAssembly().GetReferencedAssemblies().FirstOrDefault(asmName1 => asmName1.Name == assemblyName);
return Assembly.Load(asmName != null ? asmName.FullName : assemblyName);
}

Jeffrey Holmes

unread,
Jun 12, 2020, 3:47:36 AM6/12/20
to nhprof
Hi, 

I also have the same problem. Here are some of the my environment details. Has anyone got the initialization to work with the recent version of NHibernate 5.2.7 ? 

Thanks. 

NHibernate Version:                                                                                       5.2.7

HibernatingRhinos.Profiler.Appender Version:                                    4.0.4038.0

HibernatingRhinos.Profiler.Appender.NHibernateLog4Net            4.0.4038.0

 

Initializing using the following

 

HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize();

 

Exception Thrown

 

Object reference not set to an instance of an object.

 

   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)

   at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)

   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

   at HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.RegisterAppenderUsingNHibernateLogger()

   at HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.WrapLogger()

   at HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.StartNHibernateProfiling()

   at HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize(NHibernateAppenderConfiguration configuration)

   at HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize()

   at Services.App_Start.AppHost.Start() in C:\Project\App_Start\ServiceStackFramework.cs:line 434



--
Oren Eini
CEO   /   Hibernating Rhinos LTD
Skype:  ayenderahien
Support:  sup...@ravendb.net

Oren Eini (Ayende Rahien)

unread,
Jun 16, 2020, 5:18:44 AM6/16/20
to nhprof
Please upgrade to the latest version of the profiler and try again

To unsubscribe from this group and stop receiving emails from it, send an email to nhprof+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nhprof/63ad4e2f-ed89-452d-a46e-7ca49bc504d1o%40googlegroups.com.


--
Oren Eini
CEO   /   Hibernating Rhinos LTD
Skype:  ayenderahien
Support:  sup...@ravendb.net
  
Reply all
Reply to author
Forward
0 new messages