Hangfire configuration error with Asp.net (Common.Logging.Core & Common.Logging.LogManager)

I am new to Hangfire and I am having an issue with the configuration. I have posted this question to StackExchange but I am not allowed to enter the link so copying the question here

I have installed Hangfire via ‘Manage NuGet Packages’ option in Visual Studio 2012. I am using SQL Server 2008 R2 for one project and SQL Server 2012 Enterprise for another project. My project is compatible with .Net 4.0 so I couldn’t download the latest Hangfire which is compatible with .Net4.5 so I downloaded Hangfire (.Net 4.0) via NuGet.

I added a new Startup file as required by Owin & Hangfire configuration. The file is as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Hangfire;
using Hangfire.SqlServer;
using Microsoft.Owin;
using Owin;

/// <summary>
/// Summary description for Startup
/// </summary>
/// 
[assembly: OwinStartup(typeof(MyProj.Startup))]
namespace MyProj
{
    public class Startup
    {
        public Startup()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public void Configuration(IAppBuilder app)
        {
            app.UseHangfire(config =>
            {
                config.UseSqlServerStorage("ASP_NETConnectionString");
                config.UseServer();
            });
        }
    }
}

Hangfire installation automatically added following lines in the web.config:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Common.Logging.Core" publicKeyToken="af08829b84f0328e" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.6.8.0" newVersion="2.6.8.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.6.8.0" newVersion="2.6.8.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

When I run the project, I receive following error on Line 29:

Could not load type 'Common.Logging.LogManager' from assembly 'Common.Logging.Core, Version=3.0.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e'. 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

 Exception Details: System.TypeLoadException: Could not load type 'Common.Logging.LogManager' from assembly 'Common.Logging.Core, Version=3.0.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e'.

Source Error: 

Line 27:             app.UseHangfire(config =>
Line 28:             {
Line 29:                 config.UseSqlServerStorage("ASP_NETConnectionString");
Line 30:                 config.UseServer();
Line 31:             });

When I comment the dependent assembly for Common.Logging.Core in the web.config then I receive the following error on Line 30:

Could not load file or assembly 'Common.Logging.Core, Version=2.2.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040) 
  Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

 Exception Details: System.IO.FileLoadException: Could not load file or assembly 'Common.Logging.Core, Version=2.2.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Source Error: 

Line 28:             {
Line 29:                 config.UseSqlServerStorage("ASP_NETConnectionString");
Line 30:                 config.UseServer();
Line 31:             });
Line 32:         }

There seems to be a configuration issue (incompatibility) with different versions of the Common.Logging.Core dll, please note I only have one file in the bin folder for Common.Logging.Core (V3.0.0.0), I tried to find V2.2.0.0 to check if this would resolve the ‘Could not load Common.Logging.LogManager’ but I couldn’t find this dll on the web, please advice.

Please note that the installation didn’t create HangFireConfig.cs file.

Thanks for reading and any help would be highly appreciated.

Can you downgrade your Common.Logging package to 2.2.0 version?

Thanks for your reply, could you please specify the procedure for downgrading? I am new to Hangfire.

This is a NuGet procedure, not a Hangfire one :slight_smile: Just remove all packages using Common.Logging (including all Hangfire packages), then remove Common.Logging, then install Common.Logging 2.2.0, and then install Hangfire.

Thanks for clarification, I did following steps:

  1. Remove Hangfire (.Net 4), through NuGet, it automatically removed its dependencies including Common.Logging. For some reasons, it didn’t remove OWIN so I removed them separately.

  2. I used following command to install Common.Logging version 2.2.0. Please see output below from PM console:

    PM> Install-Package Common.Logging -version 2.2.0
    Attempting to resolve dependency ‘Common.Logging.Core’.
    Installing ‘Common.Logging.Core 3.0.0’.
    Successfully installed ‘Common.Logging.Core 3.0.0’.
    Installing ‘Common.Logging 2.2.0’.
    Successfully installed ‘Common.Logging 2.2.0’.
    Adding ‘Common.Logging.Core 3.0.0’ to MyProject.
    Successfully added ‘Common.Logging.Core 3.0.0’ to MyProject.
    Adding ‘Common.Logging 2.2.0’ to MyProject.
    Successfully added ‘Common.Logging 2.2.0’ to MyProject.

  3. I installed Hangfire (.Net 4) via NuGet GUI.

    I am now getting the following error:

    Could not load type ‘Common.Logging.LogManager’ from assembly ‘Common.Logging.Core, Version=3.0.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e’. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.TypeLoadException: Could not load type ‘Common.Logging.LogManager’ from assembly ‘Common.Logging.Core, Version=3.0.0.0, Culture=neutral, PublicKeyToken=af08829b84f0328e’.

Following dependencies were added automatically during installation:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Common.Logging" publicKeyToken="af08829b84f0328e" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Common.Logging.Core" publicKeyToken="af08829b84f0328e" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Threading.Tasks" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.6.8.0" newVersion="2.6.8.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.6.8.0" newVersion="2.6.8.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

Is there anyway I can upload the zip project so that this error can be locally produced at your end.

Looks like Common.Logging does not have strict dependency versions set. Look at the following line:

Successfully installed 'Common.Logging.Core 3.0.0'.

So, you can uninstall them all again, and start with installing Common.Logging.Core -Version 2.2.0, then Common.Logging -Version 2.2.0, then Hangfire packages.

I have removed everything and then followed the suggested steps. The Hangfire installation added the dependent assembly line in web.config for Common.Logging.Core 3.0.0, I commented this line and ran the project. I have two issues now:

  1. HangFireConfig file was automatically added and the system doesn’t recognise using Hangfire.Web namespace.
  2. I removed HangFireConfig file and ran the project again, and now I receive following error: ‘This operation requires IIS integrated pipeline mode.’ My project is configured to run in Classical mode. Is integrated pipeline mode is mandatory for using Hangfire?

Please advice.