Hello, I am trying to run a azure functions from a scheduled task in the game, but when I run the function it gives an error "Object reference not set to an instance of an object."
However when I run the same azure functions from inside the player's profile in the dashboard it works without any issues.
I am confused as to why the azure function is giving error only when running on scheduled task.
I did some debugging to try and find the problem, and It seems its something with the HttpRequestMessage parameter in the function, But I can't understand exactly what is going wrong with it.
Here is the code snippet.
public static async Task<dynamic> Run( [HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequestMessage req, ILogger log) { log.LogCritical("TestStart"); if(req == null){ log.LogCritical("REQ is null"); } log.LogCritical("Null Check"); var reqStr = req.ToString(); log.LogDebug("Check2"); log.LogDebug("Request String :" + reqStr); var context = await FunctionContext<dynamic>.Create(req); var args = context.FunctionArgument; Settings.TrySetSecretKey(context.ApiSettings); Settings.TrySetCloudName(context.ApiSettings); }
In the logs, when running from the dashboard from inside player profile it works, without any errors.
But when executed with the scheduled task it doesn't reach "Check2". Here is the logs in case of error :
[Information] Executing 'TestFunction' (Reason='This function was programmatically called via the host APIs.', Id=abc) [Critical] TestStart [Critical] Null Check [Error] Executed 'TestFunction' (Failed, Id=abc, Duration=33ms) Object reference not set to an instance of an object.
I did a lot of search about this issue, but could not find any case where the function did not execute on scheduled task when it does work when executing from the player info dashboard.