HangfireIO / HangfireIO/Hangfire

Instance method arguments are failing with 'target method was not found.' error in asp.net core web api

Open
#840 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
10.1k
Forks
1.8k
Avg merge
1h 19m
Merged PRs (30d)
1

Description

I've created a web api in asp.net core and trying to perform a recurring task.

below is controller code

```
public IEnumerable Get()
{
//RecurringJob.AddOrUpdate("job-one", () => Jobone.WriteLine(), new SchedulerDbContext().SchedulerConfiguration.FirstOrDefault().cronexpression); // working fine
RecurringJob.AddOrUpdate("job-one", x => x.WriteLine(), new SchedulerDbContext().SchedulerConfiguration.FirstOrDefault().cronexpression); // Failing
}
```

a call to get action triggers the job.

below is the job

```
public class Jobone
{

public void WriteLine()
{

var BasePath = AppContext.BaseDirectory;
string pathString = Path.Combine(BasePath, "Log");
DirectoryInfo di = Directory.CreateDirectory(pathString);
string fileName = "schedulerlog.txt";
pathString = Path.Combine(pathString, fileName);

using (FileStream fs = new FileStream(pathString,
FileMode.Append,
FileAccess.Write,
FileShare.Read))
using (StreamWriter writer = new StreamWriter(fs))
{
writer.WriteLine(DateTime.Now);
}

}
}
```

When the class Jobone is static, program is working as expected.
but when it is made non static program is throwing error.
below is staacktrace.

```
System.IO.FileNotFoundException

Could not load file or assembly 'dhananjay.demoproject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.

System.IO.FileNotFoundException: Could not load file or assembly 'dhananjay.demoproject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
File name: 'dhananjay.demoproject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName, ObjectHandleOnStack type, ObjectHandleOnStack keepalive)
at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean loadTypeFromPartialName)
at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)
at System.Type.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase)
at Hangfire.Storage.InvocationData.Deserialize()
```

with error message

> Failed
> Can not change the state to 'Enqueued': target method was not found.

is this a bug in library or is it something I'm doing wrong? Please Advise.

And yes, I'm checking out Hangfire from past four days and I would like to say that it is really great, works like a charm.

Additional Information -
.net core sdk version 1.1.1
windows 10

Contributor guide

Open the contributing guide

Research direction

Use the supplied controller Get action and Jobone.WriteLine method as the reproduction, then follow the failure through Hangfire.Storage.InvocationData.Deserialize. Reproduce it with the stated .NET Core SDK 1.1.1 environment; done means determining whether the non-static recurring invocation can be resolved and capturing the verified behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.