Проблема с конфигурацией Hangfire (Common.Logging.Core и Common.Logging.LogManager)

Я установил Hangfire с помощью параметра «Управление пакетами NuGet» в Visual Studio 2012. Я использую SQL Server 2008 R2 для одного проекта и SQL Server 2012 Enterprise для другого проекта. Мой проект совместим с .Net 4.0, поэтому я не смог загрузить последнюю версию Hangfire, совместимую с .Net4.5, поэтому я загрузил Hangfire (.Net 4.0) через NuGet.

Я добавил новый файл запуска, как того требует конфигурация Owin & Hangfire. Файл выглядит следующим образом:

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 автоматически добавила следующие строки в 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>

Когда я запускаю проект, я получаю следующую ошибку в строке 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:             });
 

Когда я комментирую зависимую сборку для Common.Logging.Core в файле web.config, я получаю следующую ошибку в строке 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:         }
 

Кажется, есть проблема с конфигурацией (несовместимость) с разными версиями dll Common.Logging.Core, обратите внимание, что у меня есть только один файл в папке bin для Common.Logging.Core (V3.0.0.0), я пытался найдите V2.2.0.0, чтобы проверить, решит ли это проблему «Не удалось загрузить Common.Logging.LogManager», но я не смог найти эту dll в Интернете, пожалуйста, посоветуйте.

Обратите внимание, что при установке не был создан файл HangFireConfig.cs.

Спасибо за чтение, и любая помощь будет высоко оценена.


person learner    schedule 25.02.2015    source источник
comment
Я также поднимал этот вопрос на веб-сайте Hangfire. обсудить.hangfire.io/t/   -  person learner    schedule 26.02.2015


Ответы (1)


У меня был почти такой же опыт, как у вас. Учитывая, что я использую .Net 4 и MVC 3.

Чтобы удалить Hangfire_net40, мне пришлось вручную удалить Microsoft.Bcl.Build.1.0.14 в каталоге пакета. После этого я установил common.logging.core версии 2.2.0.

Install-Package Common.Logging.Core -Version 2.2.0 

Затем переустановил hangfire_net40

Install-Package Hangfire_net40

В файле web.config я изменил строку привязки сборки для ядра common.logging на эту

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

И убедился, что ссылка в моем проекте указывает на 2.2.0, а не на 3.3.0. После этого веб-приложение запустилось нормально. Я предполагаю, что проблема в том, что пакет NuGet Hangfire_net40 выбирает неправильный пакет ядра ведения журнала.

person aggaton    schedule 09.11.2015
comment
не могли бы вы указать мне на запуск/помощь/образец Hangfire (.Net 4.0). - person bjan; 05.12.2015
comment
К сожалению, большая часть документации, которую мне удалось найти, указывает на самую последнюю итерацию HangFire. Моим лучшим источником информации был сам пакет HangFire: ..\packages\Hangfire_net40.1.1.1. Там есть небольшой файл readme с примером и некоторыми ссылками. В документации ищите версию OWIN. - person aggaton; 11.12.2015