5

Visual Studio 2012 の [NuGet パッケージの管理] オプションを使用して Hangfire をインストールしました。あるプロジェクトに SQL Server 2008 R2 を使用し、別のプロジェクトに SQL Server 2012 Enterprise を使用しています。私のプロジェクトは .Net 4.0 と互換性があるため、.Net4.5 と互換性のある最新の Hangfire をダウンロードできなかったので、NuGet 経由で Hangfire (.Net 4.0) をダウンロードしました。

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:             });
 

web.config で Common.Logging.Core の依存アセンブリにコメントすると、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:         }
 

Common.Logging.Core dll の異なるバージョンには構成の問題 (非互換性) があるようです。 V2.2.0.0 を見つけて、「Common.Logging.LogManager を読み込めませんでした」が解決されるかどうかを確認しますが、Web 上でこの dll を見つけることができませんでした。アドバイスをお願いします。

インストールでは HangFireConfig.cs ファイルが作成されないことに注意してください。

読んでくれてありがとう。どんな助けでも大歓迎です。

4

1 に答える 1

4

私もあなたとほぼ同じ経験をしました。.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" />

そして、私のプロジェクトの参照が 3.3.0 ではなく 2.2.0 を指していることを確認しました。この後、Web アプリは正常に起動しました。問題は、Hangfire_net40 NuGet パッケージが間違ったロギング コア パッケージを選択することだと思います。

于 2015-11-09T18:31:03.137 に答える