This quick blog post explains a couple of very simple fixes – essentially, user errors – to a simple problem that you might run into with Visual Studio when developing the latest of your cool Azure bits. Well, to be fair, a few simple fixes and one heavyweight. A final ditch effort to learn to live with Azurite. But we’ll get to it.
So, let’s embark on a journey, to try and make some sense of the whole Azure Storage emulating/exploring a side of things in your inner development loop. So, what is at the beginning of our journey – what was the hindrance again?
When trying to debug your solution, especially Azure Functions (but this will probably happen with some other project types as well), you’ll run into an error somewhat like this:
Azure.RequestFailedException: 'Service request failed. Status: 500 (Internal Server Error) Headers: Server: Azurite-Blob/3.14.1 Date: Mon, 08 Nov 2021 14:01:05 GMT Connection: keep-alive Keep-Alive: REDACTED Content-Length: 0 '
This is already thrown when simply starting your app, blocking you from doing much. What an annoyance.
This issue is typically caused by Azurite (the replacement for the good-old Azure Storage Emulator) being down or unreachable for whatever reason.
Annoyingly, it’s a “500 Internal Server error” that gets thrown and logged, even if it’s actually a call to a web API resulting in 404 in the background. But I guess being returned a 404 on Azure Functions startup would be even more unintuitive, right?
Now, this was annoying and super simple for me, and I know this might not help you – but I feel it’s worthwhile to document anyway.
Azurite is included in Visual Studio 2022 by default, but to my understanding, the included version is built with npm – and seems somewhat unstable. So I ended up moving to Docker instead – but a couple of the first steps in the instructions below should help with npm as well!
Time needed: 1 hour.
How to fix “Service request failed. Status: 500 (Internal Server Error)” from Azurite?
- Restart your Visual Studio
Boring, I know – but it’s a good first step.
- Update your Visual Studio version
If you’re using a Preview version of Visual Studio, update to the current (stable) one. And even if you can’t do that, for whatever reason, make sure your Visual Studio version is the latest one.
- Make sure your Visual Studio is not trying to automatically use the (also) built-in, obsolete Azure Storage Emulator
This should just cause an exception because the ports are already in use, as long as you start Azurite first. This can be shown below:
But if you want to permanently get rid of the legacy solution, just uninstall the Azure Storage Emulator altogether.
- Ditch the npm Azurite and switch over to Docker
I finally gave up – the built-in Azurite npm thingie just doesn’t work well enough for me. It’s frustrating having to restart Visual Studio or play around with command-line tools that should “just work”.
I have Docker running most of the time on my dev box anyway, so running these 2 commands will get Azurite up and running in a very lightweight Docker container:
docker pull mcr.microsoft.com/azure-storage/azurite
docker run -p 10000:10000 -p 10001:10001 -p 10002:10002 mcr.microsoft.com/azure-storage/azurite
It looks like the npm version of Azurite should yield automatically (since the ports are in use already), and you’re now good with an Azurite running in a proper Docker container.
… and now you might be good! Hopefully.
Found any other ways to fix Azurite errors? Let me know in the comments -section below!