Surviving developing .NET GRPC on MacOS

Posted on Sat 23 October 2021 in Development • 2 min read

On a daily basis, I've been primarially a mac user since 2014

That changed about 7 years ago, when I joined a startup in Jakarta, Indonesia, where the entire company (including the office boys) were mac users.

At the time, I wasn't a huge fan of making the switch over the MacOS, as I'd be primarily a Windows and Ubuntu user for my entire career, up to that point, but after a few years, I've changed my mind, and my development machine of choice for a number of years now has been a macbook pro.

The Problem

Just 2 weeks ago, I joined with a company in Pittsburgh, PA, that is developing primarily .NET services with an Angular frontend. This is all well and good, being that .NET has been supported on MacOS for a number of years now.

Aside from some smaller projects, over the last few years, we've been doing this is the first time that I'm going to be in a heavy .NET-centric environment.

Things, I'd say, have been relatively smooth, with the exception of .NET

A Hacky Work-Around

According to <this> github issue, the .NET team might consider addressing this issue at some point within .NET 6, but I think that's relatively unlikely given there seems to be very little traction on the issue.

The only current solution, right now, is to load up the GRPC services

.NET on Mac

The Article

Getting our gRPC service working on MacOS

Basically, we've got two options, moving forward.

  1. We can detect the operating system that's running our services, and disable SSL.
  2. We can just run and debug our services from within a Docker container.

Detecting the Platform

Option 2 is an entirely valid path forward, however I'd like to have the code running on the host os, rather than in a docker container for most of my development for slightly faster debug cycles, and better battery life when I'm not sitting plugged in to a wall (Docker on Mac still chews battery) from my normal

Our first problem is we need to detect whether we're environment on MacOS or some other environment.

At first, you might be tempted to do something like this

// not the way!
var thePlatform = System.Environment.OSVersion.Platform;
if (thePlatform != PlatformID.MacOSX) { /* I will always run */ }
else { /* I will never run */ }

However, you'll soon discover that on .NET Core, on MacOS the PlatformID is reported as Unix. Investigating this a bit further, the Microsoft documentation declares that the MacOSX value only worked correctly on Silverlight.

Regardless, the actual solution to detecting whether the platform is MacOS is just as simple.

using System.Runtime.InteropServices;
var isThisMac = RuntimeInformation.IsOSPlatform(OSPlatform.OSX);
if (isThisMac) { /* stuff */ }