Looks like the code that was copied from the .NET runtime had the flag check inverted!
See the issue: dotnet/runtime#1724
..and their fix PR: dotnet/runtime#32947
A small test app showing the value of IsDesktopSession..
In an SSH session:

In an interactive session:
