The type initializer for 'Hangfire.SqlServer.SqlServerObjectsInstaller' threw an exception

Hi, I’m currently in the process of setting Hangfire up and have gotten all the nuget packages with no build errors but when I try to run it I get an error saying “The type initializer for ‘Hangfire.SqlServer.SqlServerObjectsInstaller’ threw an exception.”.

I’m not sure what’s causing this as I’ve kept my code very simple just to get things started but still having issues.

public void Configuration(IAppBuilder app)
{
GlobalConfiguration.Configuration.UseSqlServerStorage(“Application_Data”);
app.UseHangfireDashboard();
}

The connection string is definitely named correctly and is pointing to a database so that’s not the problem. I tried running the install.sql file manually and then creating new SqlServerStorageOptions where PrepareSchemaIfNecessary is set to false and that was working but then started giving me a different error saying “invalid object name ‘HangFire.AggregatedCounter’.” so I’m guessing something I did wasn’t quite right.

I’ve been at it for a few hours now and not had much luck so if anyone has any ideas or could point me in the right direction, that would be great. Thanks.

So I just figured the issue out (15 minutes after posting obviously!). It turns out this issue wasn’t with Hangfire but with NLog. My Nlog.config file wasn’t setup properly and that seemed to be what was causing the issue.