Why Azure WebJob JobHost.CallAsync returns error

时间:2019-04-17 00:18:52

标签: c# .net azure azure-webjobs

Here is my code:

JobHost host = new JobHost(config);
host.CallAsync(typeof(Program).GetMethod("Auth")).GetAwaiter().GetResult();

And in WebJob Run Details I see this information:

[04/16/2019 23:21:16 > 6b9633: ERR ] 
[04/16/2019 23:21:16 > 6b9633: ERR ] Unhandled Exception: System.ArgumentNullException: Value cannot be null.
[04/16/2019 23:21:16 > 6b9633: ERR ] Parameter name: method
[04/16/2019 23:21:16 > 6b9633: ERR ]    at Microsoft.Azure.WebJobs.JobHost.CallAsync(MethodInfo method, IDictionary`2 arguments, CancellationToken cancellationToken)
[04/16/2019 23:21:16 > 6b9633: ERR ]    at XXX.Program.Main() in C:\XXX\Program.cs:line 286
[04/16/2019 23:21:16 > 6b9633: SYS INFO] Status changed to Failed
[04/16/2019 23:21:16 > 6b9633: SYS ERR ] Job failed due to exit code -532462766

I think I am using this method:

public System.Threading.Tasks.Task CallAsync(System.Reflection.MethodInfo method, [System.Threading.CancellationToken cancellationToken = null])

Member of Microsoft.Azure.WebJobs.JobHost

Summary: Calls a job method.

Parameters:

method: The job method to call.
cancellationToken: The token to monitor for cancellation requests.

Returns:

A System.Threading.Tasks.Task that will call the job method.

But looks like some override method is used.

My calling method has following signature:

private static async Task Auth()

How to call it corretly, avoiding errors?

1 个答案:

答案 0 :(得分:1)

GetMethod(string) is to get public method, but you declared it as private so it returns null. Change the method to public should work.

PS: You can use nameof keyword to avoid using string literal to identify your method typeof(Program).GetMethod(nameof(Program.Auth))