Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hangfire Configuration Issue (Common.Logging.Core & Common.Logging.LogManager)

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.

like image 759
learner Avatar asked Sep 28 '22 16:09

learner


1 Answers

I had almost the same experience as you. Given that I am using .Net 4 and MVC 3.

In order to uninstall Hangfire_net40, I had to manually delete Microsoft.Bcl.Build.1.0.14 in the package directory. After that, I installed common.logging.core version 2.2.0

Install-Package Common.Logging.Core -Version 2.2.0 

Then reinstalled hangfire_net40

Install-Package Hangfire_net40

In the web.config file I changed the assembly binding line for the common.logging core to this

<bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />

And made sure the reference in my project pointed to the 2.2.0 and not 3.3.0 After this, the web app started up fine. I guess the problem is that the Hangfire_net40 NuGet package picks the wrong logging core package.

like image 178
aggaton Avatar answered Oct 03 '22 06:10

aggaton