NHibernate Profiler does not work in .NET Core 3.1

943 views Asked by At

I'm trying to use NHibernate Profiler in a .NET Core 3.1 MVC app and although I've tried installing what the profiler insists it needs to be it's job (via nuget), I still cannot get NHibernate Profiler working with .NET Core 3.1.

I've started by adding a reference to HibernatingRhinos.Profiler.Appender to the project and have tried invoking NHibernateProfile.Initialize() from Program.Main like this:

public class Program
{
    public static void Main(string[] args)
    {
        HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize();
        CreateHostBuilder(args).Build().Run();
    }
...
}

As well as Startup's constructor

public Startup(IConfiguration configuration)
{
    HibernatingRhinos.Profiler.Appender.NHibernate.NHibernateProfiler.Initialize();
}

The first exception I received was:

System.IO.FileNotFoundException: Could not load file or assembly 'System.Configuration.ConfigurationManager, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

I added that reference via nuget.

The next exception I received was:

System.IO.FileNotFoundException: Could not load file or assembly 'System.CodeDom, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

I added the reference via nuget.

The last exception I received was the ultra-vague:

System.PlatformNotSupportedException: Operation is not supported on this platform.

NHibernate Profiler claims it works on .NET Core for the version 5.0 (I'm running build 5044) here: http://hibernatingrhinos.com/products/NHProf enter image description here

but I can't get it to work.

I haven't tried running it in the mode where you don't have to change application code, but I don't see what the point is of going through all the rigmarole of log4net when I CAN change my app code (and the docs suggest you use the the .Initialize() call anyhow)

I'm sure I'm doing something incorrectly and/or missing something. Any help would be appreciated

1

There are 1 answers

1
Michael McCarthy On

So I was right, I was doing something incorrectly.

I was foolishly copying HibernatingRhinos.Profiler.Appender.dll into the .net core project instead of using nuget to get the NHibernateProfiler package and pull in the otehr needed dependencies and specific versions for me!

I went and grabbed this package/version via nuget: enter image description here

and everything works.