This post was most recently updated on September 11th, 2020.3 min read.
I dont’ know about you, but it’s happened to me a few times: fire up your Azure functions project, hit F5 to start debugging, project builds without errors, Azure Functions host starts… And shuts down right away.
This article has a few quick and simple tips on how to extract a bit more information from Azure Functions host (func.exe), when it’s just silently failing. This means by default you won’t get any information about what’s going wrong. However, a couple of steps should get you a long way here!
This situation is frustrating to debug (nothing in Event Log, breakpoints won’t stick and the console app just disappears), but being able to extract a bit more information out of the situation might help you figure out what’s going on!
Something like below.
This window would show up for a few seconds, and then disappear.
There’s a couple of steps you can do to extract a bit more info out of your Azure Functions host. First of all, turn on breaking on all exceptions (i.e. by disabling breaking only for your code) with the following instructions.
How to enable break on all exceptions on Visual Studio 2017+:
- Open Options > Debugging > General
- Unselect “Just my code”
- See the screenshot below!
Alternatively, to avoid some edge cases with exceptions in libraries crashing your code before your breakpoints are hit, enable this setting as well:
“Break when exceptions cross AppDomain or managed/native boundaries” in Tools > Options > Debugging > General
This should enable you to grab any exceptions thrown in the code. However, the functions host might again go down in flames and you might STILL be none the wiser.
Two more steps to do, if you still don’t hit a breakpoint OR get some useful output to work with.
Enable Verbose logging for Azure Functions host
First of all, enable verbose logging for the Azure Functions host – see how on this page below:
Last resort: Run, don’t debug :|
After that, the last step – be sure to start the Azure Functions host without debugging. I know – this is super basic. Still, it’s a useful step to remember.
By default, the keybinding is Ctrl+F5 but it might be different for you. Starting without debugging should help you get SOME logging out of the execution.
With any luck, since debugging won’t crash anymore, you’ll see an actual error this time. The additional information might be helpful when trying to figure out what went wrong in your code.
For instance, I got this information, in the screenshot below.
Looks obtuse still, right? Sure, but at least it helped me in googling!
This particular error – “The system cannot find the file specified” – helped me continued the investigation I’ve described in the article below:
- How to run Robot tests on an Azure DevOps hosted agent? - March 4, 2021
- How to fix “Missing value for AzureWebJobsStorage in local.settings.json” when you’re debugging Azure Functions locally? - March 3, 2021
- How to copy-paste a table from Excel to WordPress without using plug-ins? - February 24, 2021