Debugging C# programs that run on a Linux server can be a challenge. On Ubuntu, a server may not have the Unity GUI installed, so you can’t use MonoDevelop. Even if the server had the GUI, MonoDevelop often does not work with a C# project because it doesn’t support many Visual Studio 2015 projects. Visual Studio supposedly can cross-debug a program running on Linux from a Windows box, but I haven’t been able to get one solution to work. (It does work for C++.) Xamarin Studio works, but the steps are somewhat convoluted, and won’t work if you naively follow what has been outlined by others for a Windows box (e.g., in (a), you cannot simply build the app on Linux using xbuild, because the paths for files between server and debugger host differ). Here, I note how one can get Xamarin Studio working on Windows.
- Download a copy of Xamarin Studio for Windows, and install it. Xamarin Studio for Windows is, in fact, no longer officially available, but you can still find the download here as of July 2016. I don’t know how long this link will last; you can’t download Xamarin Studio for Windows though Xamarin.com.
- In your Linux server, make sure to have it set up with a firewall, SSH, and Mono.
- Create a variable in your environment to enable Xamarin Studio “Custom Soft Debugging.” Create “MONODEVELOP_SDB_TEST” with the value “1” (no quotes) through the System Properties box.
- Start Xamarin Studio, and open or create a C# test program, like “Hello World.” Set the configuration to Debug and build the program.
- Mono does not understand PDB files, so you have to create the equivalent MDB files. Start a command-line Bash shell in the directory ‘bin/Debug/”. Type: for i in *.exe *.dll;do echo $i; pdb2mdb $i; done. If pdb2mdb is not found, make sure Mono/bin is on the search path.
- Open a command-line Bash shell on your Linux box using “ssh”, e.g., “ssh firstname.lastname@example.org”.
- In the Windows Bash shell, type: tar -cvf – Debug | ssh email@example.com ‘cat – > Debug.tar’.
- In the Linux Bash shell, type: tar -xvf Debug.tar; cd Debug; mono –debug –debugger-agent=transport=dt_socket,address=0.0.0.0:12345,server=y HelloWorld.exe, replacing HelloWorld.exe with the name of the executable you want to debug.
- In Xamarin Studio, open Run -> Run with -> Custom Command Mono Soft Debugger.
- In the pop up, enter the IP address of the Linux box, then click on “Connect”.
- You should now be able to debug your program. Note: you don’t need to compile the program on Linux. Note: if you can’t set breakpoints, it’s because you haven’t copied the .mdb files from Windows to Linux. Path names in the .mdb files are full paths, and Linux path names do not work.