Xamarin forms - debugger-agent: Unable to connect

Bumbar14 56 Reputation points
2021-05-04T19:10:57.33+00:00

Hello all,

I am trying to make test Xamarin app on android simulator. At first it was working OK, but since my app would be working also in offline mode I decided to test it on simulator without internet connection. On simulator I disabled internet and mobile data. And then error happened. I can not make app visible. Then I decided to test it this on new project. So I created new project from beginning and did not change anything. Just run it. Same thing. It does not work when no internet connection is available (both WiFi and mobile data).

I get following error (last two lines)

[monodroid-assembly] /data/app/com.companyname.test-1/base.apk entry: META-INF/MANIFEST.MF
[mono] debugger-agent: Unable to connect to 10.0.2.2:58294

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,362 questions
Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
1,002 questions
{count} votes

Accepted answer
  1. Razwill 86 Reputation points
    2021-12-10T15:18:32.427+00:00

    I don't know if this question is still relevant, but I happened to get the exact same error about a week ago. I wasted so much time on it, definitely too much, and so I want to share what I found out, so that others won't make my mistakes. After all, it's literally the first result when you google error message "[mono] debugger-agent: Unable to connect to" and I haven't found any other site mentioning this problem. So...

    If you're using a rather unusual IP 10.0.2.2 as the IP of a host with Android emulator, I think it's safe to assume you're doing the same thing that I'm doing - that is: run Windows inside of Qubes VM and Android Emulator on a host OS, presumably Linux (like me), probably because running an emulator inside of a VM is a bad thing (and also it's doesn't really work - at least for me). What I found is that connecting to the Android emulator on the host OS is quite easy - you just need to type adb connect 10.0.2.2 in CMD in Windows (guest OS) and the running Android emulator will show up when you type adb devices.
    (Also, just a quick sidenote tip which would also save me a lot of time - if when you type the aforementioned command you get an "unauthorized device" message try opening an Android emulator without Play services - it solved the problem for me).
    Now that's when the problem occurs. When I start debugging in Visual Studio everything works well, the app is built successfully and is starting on the device emulator, but then, after literally a second being opened, it crashes - Android emulator comes back to the home screen and in Visual Studio the last (and only) error message I get is [mono] debugger-agent: Unable to connect to 10.0.2.2:[random port here]. To be honest it is quite frustrating, because it doesn't tell you why it can't connect to the device. I tried turning the output verbosity to maximum everywhere it's possible, but it still just says that it can't connect and that's all.
    To be clear - I can open the app - if I press "Start without debugging" in Visual Studio the app starts on the Android emulator. I just can't debug it - and that's quite important. Also, without debugger the XAML Hot Reload feature doesn't work and that's a quite useful feature - at least in some cases.
    Anyway, after being frustrated with it for a long time I tried doing things that - as I thought - shouldn't work. And one of those things obviously did work.

    The thing that solved everything for me is just restarting the Android emulator as root. To do that you just need to write in CMD in Windows (the guest OS):
    adb -s 10.0.2.2:5555 root
    The IP is that of the host with Android emulator - in your case the IP address should be the same.
    The only thing that's left is that now in Visual Studio a new Android device shows up called "unknown Android SDK built for x86 ([version of Android SDK])". That's the device that you should now connect to and debug on. Don't know why's that a case, but it works for me.

    As I said - I don't know if what I wrote applies to you, but I wrote it down anyway as a resource for other. I hope I helped at least someone.

    2 people found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Allan Aleluia 5 Reputation points
    2023-04-02T17:30:59.1533333+00:00

    I just went through the SAME problem.

    I tried the alternatives presented here and simply couldn't find where to change the connection address of the HOST.

    I decided to create another device and run the application through it and it worked.

    Would it be the right way? I do not think so. But it worked and that's what matters, even more so in a test or study environment.

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.