Hangfire Dashboard: Recurring Job Can not find the target method.

Created on 21 Apr 2016  ·  10Comments  ·  Source: HangfireIO/Hangfire

Hi i'm trying hangfire to see if we could use it in our project.

I'm having a problem wherein the dashboard could not find the assembly where my background method is.

image

But the weird thing is hangfire server is able to execute it

image

image

I have a console app as a Hangfire server and I use Windsor as my container. Basically this code will create recurring jobs.

1 recurring job will be referenced from a 'common project' which is the 'ISampleClass'

namespace HangfireConsoleApp
{
    public class Program
    {
        static void Main()
        {

            WindsorContainer container = new WindsorContainer();
            container.Register(Component.For<ISampleClass>().ImplementedBy(typeof(SampleClass)).LifestyleSingleton());

            GlobalConfiguration.Configuration.UseSqlServerStorage("HangfirePOCCx");
            GlobalConfiguration.Configuration.UseActivator(new ContainerJobActivator(container));

            using (var server = new BackgroundJobServer())
            {
                Console.WriteLine("Hangfire Server started. Press any key to exit...");

                RecurringJob.AddOrUpdate(() => Console.WriteLine("Hello from console app, i'm running every minute"), Cron.Minutely);

                RecurringJob.AddOrUpdate<ISampleClass>(x => x.SampleMethod(), Cron.Minutely);                

                Console.ReadKey();
            }
        }
    }
}

My common class looks like

namespace HangfirePOC.Common
{

    public class SampleClass : ISampleClass
    {
        [DisplayName("Sample Method")]
        public void SampleMethod()
        {
            Console.WriteLine("Hello! I am Sample Method");
        }
    }


    public interface ISampleClass
    {
        void SampleMethod();
    }
}

and my dashboard which is in a separate web project looks like

using System;
using System.Threading.Tasks;
using Hangfire;
using Hangfire.SqlServer;
using Microsoft.Owin;
using Owin;

[assembly: OwinStartup(typeof(HangfireDashboard.Startup))]

namespace HangfireDashboard
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            // Map Dashboard to the `http://<your-app>/hangfire` URL.
            app.UseHangfireDashboard("/hangfire",new DashboardOptions(),new SqlServerStorage("HangfirePOCCx"));
        }
    }
}


Am i missing any configuration?
Thanks in advance! :)

Update

I tried the same scenario with background job and I am having the same problem.

Btw these are the packages that i am using

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Castle.Core" version="3.3.0" targetFramework="net45" />
  <package id="Castle.Windsor" version="3.3.0" targetFramework="net45" />
  <package id="Hangfire.Core" version="1.5.5" targetFramework="net45" />
  <package id="Hangfire.SqlServer" version="1.5.5" targetFramework="net45" />
  <package id="HangFire.Windsor" version="0.1.5343.14974" targetFramework="net45" />
  <package id="Newtonsoft.Json" version="5.0.1" targetFramework="net45" />
  <package id="Owin" version="1.0" targetFramework="net45" />
</packages>


question

Most helpful comment

Is there more news on this matter?

We are going to run multiple background servers and one dashboard asp,net site. To reference every project in the dashboard site is just not good practice and feels wrong.

Isn't there an alternative way of displaying the names?

All 10 comments

Alright i got this working!

The cause of my problem is my dashboard project does not have a REFERENCE in my 'common project' hence it could not find the assembly and the [DisplayName] attribute does not work.

So to fix it I just referenced the assembly needed so my dashboard could display the names properly.

:+1: for Hangfire :)

Cheers!

Haai,

I'm also getting this issue, but only adding the reference is not working.

A limited view of what I have:

Console Project (BackgroundJobServer)
Web Project (Dashboard)
Common Libraries - there's 1 common one that contains the jobs and it's interfaces, which is referenced by both of the above.

I have a RecurringJob that that completes successfully, and shows fine in the dashboard - but this recurring job fires of normal BackgroundJob.Enqueue(x => x.Run()); jobs - these ones show "Can not find the target method." in the dashboard.

Any idea why?

Is there more news on this matter?

We are going to run multiple background servers and one dashboard asp,net site. To reference every project in the dashboard site is just not good practice and feels wrong.

Isn't there an alternative way of displaying the names?

I also have same issue. But I try to move the method which contains ' BackgroundJob.Enqueue ' to a vm class . When I want to call this method . I will new a vm class . Then use vm to call the method . It's successful . I think the reason is some resource is used by two object in the same time. I have 6 method well call 'BackgroundJob.Enqueue ' . Anyway it can run .I hope this can help you.

My exception is like below

warn: Hangfire.AutomaticRetryAttribute[0]
Failed to process the job '15': an exception occurred. Retry attempt 3 of 10 will be performed in 00:01:01.
`System.IO.FileNotFoundException: 未能加载文件或程序集“DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null”或它的某一个依赖项。系统找不到指定的文件。 文件名:“DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null” 在 System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type) 在 System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName) 在 System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase) 在 Hangfire.Storage.InvocationData.Deserialize()

=== 预绑定状态信息 === 日志: DisplayName = DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null (Fully-specified) 日志: Appbase = file:///D:/Code/Test/bin/Debug/net461/ 日志: 初始 PrivatePath = NULL

调用程序集: Hangfire.Core, Version=1.6.19.0, Culture=neutral, PublicKeyToken=null。`

日志: 此绑定从 default 加载上下文开始。 日志: 正在使用应用程序配置文件: D:\Code\Test\bin\Debug\net461\ Test.exe.Config 日志: 使用主机配置文件: 日志: 使用 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\config\machine.config 的计算机配置文件。 日志: 此时没有为引用应用策略(私有、自定义、分部或基于位置的程序集绑定)。 日志: 相同的绑定已出现过,因 hr = 0x80070002 而失败。

@reggieboyYEAH Thanks for your post. I even faced the same problem. I have referenced the dll and resolved it.

Haai,

I'm also getting this issue, but only adding the reference is not working.

A limited view of what I have:

Console Project (BackgroundJobServer)
Web Project (Dashboard)
Common Libraries - there's 1 common one that contains the jobs and it's interfaces, which is referenced by both of the above.

I have a RecurringJob that that completes successfully, and shows fine in the dashboard - but this recurring job fires of normal BackgroundJob.Enqueue(x => x.Run()); jobs - these ones show "Can not find the target method." in the dashboard.

Any idea why?

I have the same situation.

Both webapp and the console app reference my shared project which contains the "background jobs" but I am getting failed hangfire jobs with exception: "System.IO.FileNotFoundException: Could not load file or assembly"

Anyone every find a solution to this? My recurring jobs work and then stop working with this error until I for a "Trigger Now" from the dashboard and then they start working again. Stop and restart the server component and they stop working again until I manually trigger them again. I've spent two days on Hangfire and am about to give up on it due to the lack of reliability.

Haai,

I'm also getting this issue, but only adding the reference is not working.

A limited view of what I have:

Console Project (BackgroundJobServer)
Web Project (Dashboard)
Common Libraries - there's 1 common one that contains the jobs and it's interfaces, which is referenced by both of the above.

I have a RecurringJob that that completes successfully, and shows fine in the dashboard - but this recurring job fires of normal BackgroundJob.Enqueue(x => x.Run()); jobs - these ones show "Can not find the target method." in the dashboard.

Any idea why?

Hi Werner

Did you ever figure out how to solve this issue?

In case anyone else finds themselves down this particular rabbit hole ...

In order for Hangfire dashboard to display the job being enqueued the enqueue call needs to be

_hangfireServer.Enqueue<ISomeWorkerInterface>(x => x.Process(someIdentifier));

as opposed to

_hangfireServer.Enqueue(() => _someWorkerInterface.Process(someIdentifier));

The Queue and JobDisplayName attributes are on the interface (ISomeWorkerInterface) and not its concrete implementation.

My code is as follows:

public class TableSyncJob : AsyncBackgroundJob<MapTable>, ITransientDependency
{
  private readonly IMapProjectRepository _projectRepository;
  public TableSyncJob(IMapProjectRepository projectRepository)
  {
      _projectRepository = projectRepository;
  }

   [UnitOfWork]
  public override async Task ExecuteAsync(MapTable args)
  {
      // TODO
  }
}

AddOrUpdate Job:

var tableJob = _serviceProvider.GetRequiredService<TableSyncJob>();
RecurringJob.AddOrUpdate(jobName, () => tableJob.ExecuteAsync(eventData.Entity), CronType.Minute());

Error Info:
image

I think it is [UnitOfwork], but the corresponding assembly is definitely.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tompazourek picture tompazourek  ·  3Comments

cindro picture cindro  ·  3Comments

nsnail picture nsnail  ·  3Comments

cottsak picture cottsak  ·  3Comments

abdelrady picture abdelrady  ·  4Comments