This article shows you how to troubleshoot a specific symptom that you may encounter when you have Durable Function with Dependency Injection.
Durable Functions are an extension of Azure Functions that lets you write stateful functions in a server less environment. The extension manages state, checkpoints, and restarts for you.
We know that the output of one function becomes the input of another functions. But what if the first function output is “Null”? You see exception as “Value cannot be Null”.
You may see “System.ArgumentNullException” for your Function App which uses Dependency Injection
Cause of the Issue
While using the Dependency Injection, it is recommended, and best practice to, not use “static” variable which could change.
The issue is that the initialization code is not always called on a given instance of the function app. This is also why we see functions always succeeding or never succeeding on a given instance.
It’s extremely important to note that instance setup should not be done by an unrelated function, because there are no guarantees about which functions run where (that’s the power of server less scale). On startup of the instance or through dependency injection, any initialization code should be done. It’s dangerous to use a static variable that can be changed, again, because there are no guarantees about which functions run where and when.
To mitigate the issue, we can add the “runOnStartup = true” on configuration.
This is a very hacky solution for initialization code, but this is a quick way to mitigate their issue while a longer-term solution is put in place.
Authored By - Shashank Ranjan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.