I have been using Azure Functions for quite a while now without any issues. Setting them up is easy, and once they are running all is good. And as you can even load PnP PowerShell into them it is fairly easy to run some automation logic in the cloud. Now there also Azure Runbooks but for the sake of client context lest assume you have an Azure Function for reasons.
For reasons that are still unclear to me suddenly one of the Azure Functions that was build over a few months ago started to encounter some issues. It couldn’t load PnP Modules anymore. The DLL’s where present in the correct folder, but it kept throwing an error.
Exception while executing function: Functions.FunctionName. System.Management.Automation: Could not load file or assembly 'OfficeDevPnP.Core, Version=3.16.1912.0, Culture=neutral, PublicKeyToken=5e633289e95c321a' or one of its dependencies. The system cannot find the file specified. mscorlib: Could not load file or assembly 'OfficeDevPnP.Core, Version=3.16.1912.0, Culture=neutral, PublicKeyToken=5e633289e95c321a' or one of its dependencies. The system cannot find the file specified.
It took me quite some debugging to figure out a solution. I tried updating the modules to a newer PnP version but that didn’t work. I made sure all settings related to connections where updated to TLS 1.1/1.2 but to no avail. I even recreated a new function in the same app but that didn’t work either. Now the weird thing was the function was running flawlessly for a few months. And monitoring was in place so I could see the exact error occurring even though no changes had been made.
Now in the ‘old’ days you would just reboot the stuff and see what happens. And that triggered me to try and recycle the app pool the Function was running on. If you would go to your Azure Function page you will see the option to try the new Azure Function management experience:
This will look a lot like the App Service plan page and will provide you with the option to restart your app service. This will recycle the app service the function is using. It felt like restarting my app pool but once done it started working again.
Now I do not have any clue why it failed in the first place, but at least I could solve the issue and move on. Perhaps due to some of the scaling issues of the last week something got ‘stuck’. Or it was just bad luck. I was happy it solved my issue and I will make sure to keep an eye out of any other unexpected behavior.