Cannot debug on device: connection refused

Hello, I am having trouble debugging my App on an Android device via Mono/VS on a PC.

  • Device: Samsung Galaxy S6 (SM-G920F, Android 7.0)
  • The device is properly connected to adb via WiFi, logcat works flawlessly.
  • Firewall and antivirus disabled on both, Windows PC and Smartphone.
  • The smartphone is in developer mode with USB debugging enabled and my app is selected as the debug target in the developer menu.
  • I verified multicast is working properly in my network.
  • PC and smartphone can reach each other (ping)
  • The device properly shows up in the IDEs Attach Debugger menu.
  • The build is a development build with script debugging enabled, device filter FAT, runtime .net 3.5 equivalent, backend mono

When trying to attach the debugger, the following happens:

  • Mono: Error-message “Could not connect to the debugger”. When attaching a debugger to Mono, the following Exception pops up: System.Net.Sockets.SocketException: ‘No connection could be made because the target machine actively refused it 192.168.1.136:56921’

  • VS 2017: Nothing happens. When attaching a debugger to VS, the following is printed to the output:
    Exception : Unable to start program ‘Unity’. Operation not supported. Unknown error: 0x80004005.

Please help, I already invested a lot of time into something that should be working from the start - this makes Unity unusable for me.

So this is funny, I left the PC in standby for 2 hours, and now its working, out of the blue, no changes done - what is this black magic? Were to many ports used up from trying to fix this all day? Please Unity, improve the error handling and give better error messages!

The issue appeared again after I switched the project to il2cpp - maybe this was the issue I had above because I did play with this setting before. I tried switching between il2cpp and mono three times, each time debugging the mono version worked, il2cpp never (fresh project). Can someone reproduce this?

Also: .net 4.6 + mono causes the app to crash on startup for me (I guess this issue: Unity Issue Tracker - [Android] Script debugging causes Android to crash on startup with .NET 4.6). This leaves me with the only option: .net 3.5 + mono…

Just in case, you didn’t see - https://docs.unity3d.com/Manual/AttachingMonoDevelopDebuggerToAnAndroidDevice.html

@Tomas1856 : thanks, all of that is properly set up, it’s not the issue. I am waiting for someone to reproduce the il2cpp debugging issue and will then file a bug report.

Same issue here… switching to mono backend allowed us to attach the debugger…