首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Hangfire配置问题(Common.Logging.Core & Common.Logging.LogManager)

Hangfire配置问题(Common.Logging.Core & Common.Logging.LogManager)
EN

Stack Overflow用户
提问于 2015-02-25 16:47:42
回答 1查看 3.8K关注 0票数 5

我已经在Visual 2012中通过“管理NuGet包”选项安装了Hangfire。一个项目使用Server 2008 R2,另一个项目使用SQLServer2012Enterprise。我的项目与.Net 4.0兼容,所以我无法下载与.Net4.5兼容的最新Hangfire,所以我通过NuGet下载了Hangfire (.Net 4.0)。

我按照Owin & Hangfire配置的要求添加了一个新的启动文件。档案如下:

代码语言:javascript
复制
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中自动添加了以下行:

代码语言:javascript
复制
  <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行上收到以下错误:

代码语言:javascript
复制
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行上收到以下错误

代码语言:javascript
复制
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似乎存在配置问题(不兼容),请注意,我在Common.Logging.Core的bin文件夹中只有一个文件(V3.0.0.0),我试图查找V2.2.0.0来检查这是否会解决“无法加载Common.Logging.LogManager”的问题,但我在网上找不到这个dll,请注意。

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

感谢您的阅读和任何帮助,将不胜感激。

EN

回答 1

Stack Overflow用户

发布于 2015-11-09 18:31:03

我和你的经历几乎一样。考虑到我使用的是.Net 4和MVC 3。

为了卸载Hangfire_net40,我不得不手动删除包目录中的Microsoft.Bcl.Build.1.0.14。之后,我安装了common.logging.core版本2.2.0

代码语言:javascript
复制
Install-Package Common.Logging.Core -Version 2.2.0 

然后重新安装hangfire_net40

代码语言:javascript
复制
Install-Package Hangfire_net40

在web.config文件中,我将common.logging核心的程序集绑定行更改为

代码语言:javascript
复制
<bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />

并确保我的项目中的引用指向2.2.0,而不是3.3.0之后,web应用程序启动良好。我猜问题在于Hangfire_net40 NuGet包选择了错误的日志核心包。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28724744

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档