Owin不包含“UseHangfire”的定义,也没有扩展方法“UseHangfire”

时间:2015-01-12 17:27:44

标签: c# asp.net hangfire

我正在尝试在VS 2013中设置Hangfire,我已经通过Package Manager安装了它。但是,当我添加http://docs.hangfire.io/en/latest/quick-start.html中所述的app.UseHangfire(...)代码时。我收到以下错误:

'Owin.IAppBuilder' does not contain a definition for 'UseHangfire' and no extension method 'UseHangfire' accepting a first argument of type 'Owin.IAppBuilder' could be found (are you missing a using directive or an assembly reference?)

2 个答案:

答案 0 :(得分:6)

您是否添加了命名空间?

using Hangfire;

您的Startup应该是这样的:

using Hangfire;
using Hangfire.SqlServer;
using Hangfire.Dashboard;

public class Startup
{
    public void Configuration(IAppBuilder app)
        {
            app.UseHangfire(config =>
            {
                config.UseSqlServerStorage("Data Source=<connectionstring>; Initial Catalog=HangFire; Trusted_Connection=true;");
                config.UseServer();

                //config.UseAuthorizationFilters(new AuthorizationFilter
                //{
                //    // Users = "admin, superuser", // allow only specified users
                //    Roles = "admins" // allow only specified roles
                //});
            });
    }
}

答案 1 :(得分:0)

将HangFire.Core包更新到最新版本为我解决了这个问题。似乎OWIN正在安装旧包作为依赖