Debugging C# on Ubuntu and you get

So you’re trying to debug C# code on Linux, maybe Ubuntu. You’ve installed .NET 6 or 7, you’ve built your solution in Visual Studio on your Windows PC, published it then copied the files over to the Linux box. But when you run it, you get an error “Unable to find debugger script at”. It’s time to debug your Linux app from your Windows Visual Studio.
Now there is a Microsoft support issue for this and it’s less than helpful. Read below to see how I fixed it.
Only, as soon as it tries to attach over SSH (with username, password, IP etc), you get this popup on the left. “Computer says no”.
Looking in the VS Output folder you see the text below or something similar. For whatever reason, it failed to create a hidden folder in your home folder. To fix this, all you have to do is create that folder. It’s .vs-debugger under your home folder.
If you’re not familiar with .folders on Linux, note that the . at the front of the name means it’s a hidden folder. A simple ls command will not reveal it. If you use the File Manager, you can click the settings in the top right and tick the Show Hidden Files. Then you can do a cd ~ followed by a mkdir .vs-debugger. And View in files to confirm that it’s there.
Now the only pain with debugging is that the application must be running for Visual Studio to attach to it. I was debugging a utility that is run, does its business and closes. So to debug it, I added this as the first line in main() in program.cs
Console.ReadKey();
So run it, let it sit waiting for a key then attach visual studio’s debugger to your app over SSH, add your breakpoints and hit a key. Simples!
It’s been a few years since I compiled the code for the first eBook and I needed to create an SDL application on Windows. I copied a project, as it was the fastest way to setup the include and lib paths, and the lib files needed to compile.
On Linux (Ubuntu and Raspberry Pi OS) I use Visual Studio Code, but compiling or more specifically on the Terminal menu, Run Build Task defaults to Ctrl-Shift-B. Being lazy and a long time user of Visual Studio with it’s F6 key, I decided to change this.
I’m aware that C is notorious for unexpected behaviour (UB). Let me describe this bug:
Remember the cellular automation Life? I covered it in previous blog entries
I occasionally write answers on Quora.com and many recurring questions are about assembly language. Now I used to write games in 6502 and Z80 assembly language when the only alternative was Basic. But assembly language is very tedious to write, painstaking and it’s slow to write programs in assembly language. Most of your code is moving values between memory and registers or vice versa.
Every month a new Tiobe Index is published purporting to show the most popular programming languages. Except, if you look at other programming language popularity surveys, lists etc, the Tiobe Index increasingly seems to be at odds with everybody else.
Toptal.com is a site for recruiting freelances for projects. They have
There’s nothing worse than a program halting with a simple “Segmentation fault” and no idea where or why. It happened to me today working on the 2nd eBook (for Raspberry Pi) and I had to figure out where it was going wrong.