Skip to content

Commit c7037e9

Browse files
committed
Fix JobLoadException when using interface method as a background job
Closes HangfireIO#463
1 parent 7f83388 commit c7037e9

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

‎src/Hangfire.Core/Storage/InvocationData.cs‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,14 @@ private static object DeserializeArgument(string argument, Type type)
172172

173173
private static IEnumerable<MethodInfo> GetAllMethods(Type type)
174174
{
175-
return type.IsInterface ? type.GetInterfaces().SelectMany(x => x.GetMethods()) : type.GetMethods();
175+
var methods = new List<MethodInfo>(type.GetMethods());
176+
177+
if (type.IsInterface)
178+
{
179+
methods.AddRange(type.GetInterfaces().SelectMany(x => x.GetMethods()));
180+
}
181+
182+
return methods;
176183
}
177184

178185
private static MethodInfo GetNonOpenMatchingMethod(Type type, string name, Type[] parameterTypes)

‎tests/Hangfire.Core.Tests/Storage/InvocationDataFacts.cs‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,20 @@ public void Deserialize_HandlesGenericMethods_WithOpenTypeParameters()
9696
Assert.False(job.Method.ContainsGenericParameters);
9797
}
9898

99+
[Fact]
100+
public void Deserialize_HandlesMethodsDefinedInInterfaces()
101+
{
102+
var serializedData = new InvocationData(
103+
typeof(IParent).AssemblyQualifiedName,
104+
"Method",
105+
JobHelper.ToJson(new string[0]),
106+
JobHelper.ToJson(new string[0]));
107+
108+
var job = serializedData.Deserialize();
109+
110+
Assert.Equal(typeof(IParent), job.Type);
111+
}
112+
99113
[Fact]
100114
public void Deserialize_HandlesMethodsDefinedInParentInterfaces()
101115
{

0 commit comments

Comments
 (0)