【问题标题】:Hangfire Configuration Issue (Common.Logging.Core & Common.Logging.LogManager)Hangfire 配置问题 (Common.Logging.Core & Common.Logging.LogManager)
【发布时间】:2015-02-25 16:47:42
【问题描述】:

我已经通过 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 的不同版本似乎存在配置问题(不兼容),请注意我的 bin 文件夹中只有一个文件 Common.Logging.Core (V3.0.0.0),我试图找到 V2.2.0.0 来检查这是否能解决“无法加载 Common.Logging.LogManager”但我在网络上找不到这个 dll,请指教。

请注意,安装没有创建 HangFireConfig.cs 文件。

感谢您的阅读,我们将不胜感激。

【问题讨论】:

标签: c# asp.net sql-server-2008-r2 owin hangfire


【解决方案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 在此之后,网络应用程序启动正常。 我猜问题是 Hangfire_net40 NuGet 包选择了错误的日志核心包。

【讨论】:

  • 能否请您指出 Hangfire (.Net 4.0) 的启动/帮助/示例。
  • 不幸的是,我能够挖掘到的大多数文档都指向了 HangFire 的最新迭代。我最好的信息来源是 HangFire 包本身:..\packages\Hangfire_net40.1.1.1。里面有一个小的自述文件,里面有一个例子和一些链接。在文档中查找 OWIN 版本。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多