Things I Learned #19: MacOS, Dotnet, and Azure Functions

4 minute read til learning   macos   dotnet   azure Comments

I do almost all of my development in an Azure-hosted Windows Virtual Machine on my current project. It works well and keeps my Mac from being cluttered with client-specific artifacts, including code, environment variables, databases, etc. I can easily spin it up when I need it and shut it down when I don't.

One of the other teams working on this project has taken a different approach. They are all on Macs and have decided to get the complete development environment running in Docker. They spin up the Docker containers they need, connect to them using JetBrains Rider, and then develop their features, etc. Everything is built and runs within the containers. It's a cool setup and one I was immediately intrigued by since I love working on my Mac and my virtual machine has been giving me problems lately.

As I followed along with the README the other team created, I was on step 3 or 4 when I ran into a problem that stopped me. One of the projects was throwing an exception during the build. A local, non-Docker build was occurring, so I immediately started looking at Rider to see if I had something misconfigured.

The exception being throw was during the build of an Azure Functions project

Metadata generation failed. Exit code: '137' Error: 'Failed to Initialize CoreCLR'

My initial search told me it might be due to a mismatch with .NET versions. While the project is in .NET 6, .NET 7 was the default on my machine. 7.0 was installed at the same time as Visual Studio for Mac, which I haven't used, so I decided to delete both from my system.

I continued to see the exception no matter what I tried. I installed the latest version of "Azure Functions Core Tools" and made sure the plugin was installed in Rider. Still, no go.

I worked closely with one of the devs on the other team who had all of this running on his machine. While being new to Macs himself, he made an interesting comment: "when it comes to Macs, it all depends on the setup, and different people with the same hardware and same OS can have different outcomes depending on a myriad of factors." I don't disagree.

The work with the other developer did prove one thing - the problem had nothing to do with Rider, and was simply to do with my system configuration. Go figure. As we disconnected from our last call, I'm sure he was thinking, "good luck, but it works on my machine."

Google searches were NOT giving me actionable results so I finally posted something on Mastodon hoping *someone, somewhere* could help.

A post on Mastodon that says On my Mac with the Azure Functions Core Tools@4 installed, I'm unable to build/run any Azure Functions. The error is: Metadata generation failed. Exit code: '137' Error: 'Failed to Initialize CoreCLR' I can build and run other types of dotnet projects, just not Azure Functions. What am I missing? Is this expected? It can't be expected, right? dotnet 6.0.403 is installed.

That post brought a lot of boosts, but only one potential lead, a link to this issue on GitHub.

Unfortunately, that issue is littered with a lot of things that didn't make a lot of sense to me including reinstalling versions of Dotnet that A) I already had installed, or B) that should have nothing to do with the behavior I was seeing.


I learned that sometimes your system just has too much junk on it that causes unforeseen issues.

When I ran

dotnet --list-sdks
I was presented with a long list of installed SDKs, going all the way back to early versions of 3.0.

By this time, I was getting frustrated and decided I was going to do what the GitHub issue mentioned and simply reinstall Dotnet 5. It made no sense, but at least it was something.

Before doing that, I decided to clean up my system and rid myself of all those old versions I no longer needed or cared about. Off to the races, I grabbed the uninstall tool from GitHub and started eliminating all the old SDKs and runtimes. I probably deleted a dozen of each before I was left with a couple versions of 5.0 and then my current 6.0.405. Since I *thought* I was going to simply uninstall and reinstall the latest 5.0, I blew all remaining SDKs and runtimes with the exception of 6.0.405.

Before doing anything else, and with only 6.0.405 installed, I decided to try building the Azure Functions project again. It makes absolutely NO sense at all, but that seemed to do the trick. I am now able to build and run Azure Functions on my Mac.

Now I have a bunch of questions! I wonder if things would have worked if I had simply reinstalled 6.0.405. I wonder why it didn't work with 7.0 installed. What if I had removed the 5.* versions and reinstalled? Would that have also fixed it like the GitHub issue mentioned? I'd love to install earlier versions and see if building Azure Functions breaks again.

By the way, what I really learned is that technology can be frustrating for no good reason.

I am grateful I was able to get it working, I just wish it had been for a better reason than "too much old junk" on my system.