我在Visual Studio 2012中通過“管理NuGet包”選項(xiàng)安裝了Hangfire.我將SQL Server 2008 R2用于一個(gè)項(xiàng)目,將SQL Server 2012 Enterprise用于另一個(gè)項(xiàng)目.我的項(xiàng)目與.Net 4.0兼容,所以我無法下載與.Net4.5兼容的最新Hangfire,所以我通過NuGet下載了Hangfire(.Net 4.0).
我根據(jù)Owin& amp;的要求添加了一個(gè)新的啟動(dòng)文件. 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安裝會(huì)自動(dòng)在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>
當(dāng)我運(yùn)行該項(xiàng)目時(shí),我在第29行收到以下錯(cuò)誤:
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: });
當(dāng)我在web.config中注釋Common.Logging.Core的依賴程序集時(shí),我在第30行收到以下錯(cuò)誤:
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: }
似乎有一個(gè)配置問題(不兼容)與不同版本的Common.Logging.Core dll,請(qǐng)注意我只有一個(gè)文件在bin文件夾中的Common.Logging.Core(V3.0.0.0),我試過找到V2.2.0.0來檢查這是否會(huì)解決’無法加載Common.Logging.LogManager’但我在網(wǎng)上找不到這個(gè)dll,請(qǐng)指教.
請(qǐng)注意,安裝沒有創(chuàng)建HangFireConfig.cs文件.
感謝閱讀和任何幫助將非常感謝. 解決方法: 我和你幾乎有過相同的經(jīng)歷.鑒于我正在使用.Net 4和MVC 3.
為了卸載Hangfire_net40,我不得不在包目錄中手動(dòng)刪除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核心的程序集綁定行更改為this
<bindingRedirect oldVersion="0.0.0.0-2.2.0.0" newVersion="2.2.0.0" />
并確保我的項(xiàng)目中的引用指向2.2.0而不是3.3.0 在此之后,網(wǎng)絡(luò)應(yīng)用程序啟動(dòng)正常. 我想問題是Hangfire_net40 NuGet包選擇了錯(cuò)誤的日志核心包. 來源:https://www./content-1-262801.html
|