Function App using Dependency Injection throwing "System.ArgumentNullException”
Published Aug 16 2019 02:17 AM 2,865 Views



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

Version history
Last update:
‎Aug 24 2020 12:38 PM
Updated by: