20 February 2016

Fix for “could not connect to the debugger” while deploying Xamarin Forms apps to the Visual Studio Android Emulator

While I was busy developing a cross-platform application for Windows Phone, Android and iOS I wanted to test the Android implementation and ran into a snare – I could no longer debug on the emulator. This kept me puzzled for a while, and only with the combined help of my fellow MVPs Mayur Tendelkar and Tom Verhoeff, who both had pieces of the puzzle, I was able to finally get this working.

As you try to deploy an app to the Visual Studio Android emulator, symptoms are as follows:

  • The app is deployed
  • The app starts on the emulator
  • It immediately stops
  • You get one or more of the following messages in your output window:

AOT module 'mscorlib.dll.so' not found: dlopen failed: library "/data/app/<your app name>.Droid-1/lib/x86/libaot-mscorlib.dll.so" not found

Android application is debugging.
Could not connect to the debugger.

This actually even happens when you do File/New Project and run, which is very frustrating. Oddly enough, when you start the deployed app on the emulator by clicking on it, it runs fine. The issue is solely the debugger not being able to connect.

The first error – the missing libaot-mscorlib.dll.so, which is usually hidden in a plethora of messages - is easy to fix: disable Android fast deployment. Go to the properties of the Android project, hit tab “Android options”, and unselect “Use Fast Deployment”


That will usually take care of the libaot-mscorlib.dll.so issue. Not an obvious thing to do, but hey, that’s almost nothing in our field. But still my debugger would not connect. The solution to that takes the following steps, which are even less obvious:

  • Start the Hyper-V manager
  • Select the emulator you are trying to use
  • Right-click, hit settings


  • Click processor
  • Click Compatibility
  • Click checkbox “Migrate to a physical computer with a different processor version”


And of course, once you know that, you can find people have encountered this problem before, like here in the MSDN forums, on Stackoverflow or even here in comments on the release notes of the emulator. The fact that the solution is hard to find with only the error message made me decide to write a blog post about it anyway.

This issue only seems to be occurring on the newer generation of processors, which explains why I never saw it before – I ran this on a brand new Surface Pro 4, where I used to run the emulators on my big *ss desktop PC, whose i7 processor dates back to 2011. It’s one of ye good olden 970 3.20 Ghz monsters, from the time power efficiency was not quite very high on the Intel agenda yet ;) It’s the 1939 Buick Hot Rod of the i7’s, but as a bonus, I never have to turn on the heating in the study on cold winter days :)

By the way, if the android emulator seems to be stuck in  the “preparing” phase, you might want to check if you have internet connection sharing enabled – it does not seem to like that either.

Thanks Mayur and Tom, you have been a great help, as always.


Jonathan Pryor said...

This message:

AOT module 'mscorlib.dll.so' not found: dlopen failed: library "/data/app/.Droid-1/lib/x86/libaot-mscorlib.dll.so" not found

Is not an error message. It's a diagnostic message (which is why in adb logcat it contains a D category). The AOT message is not at all related to the debugger connection.

Furthermore, by disabling Fast Deployment, you're ensuring you have a worse development experience, as you are ensuring that every change will rebuild and redeploy the .apk.

Greg Munn said...

"AOT module 'mscorlib.dll.so' not found: dlopen failed: library "/data/app/.Droid-1/lib/x86/libaot-mscorlib.dll.so" not found" is a diagnostic message and not an actual error message.

Joost van Schaik said...

@Jonathan @Greg but at least it works. I tend to prefer something that works slowly over something that fails fast :). I got the tip from a Xamarin person.

gzidar said...

Thank you so much for this blog post. This is one of those problems that could have caused me many hours of frustration. Much appreciated.

Joost van Schaik said...

@gizdar I know. Been there, done that. I want to prevent other people falling into the traps I did fall into. I hope more people will do so as well.

Alessio Simoni said...

I was going crazy with this problem, thank you Joost (and thanks for your amazing library "WpWinNl" that I used in my app Traffic https://www.microsoft.com/store/apps/9wzdncrfhx2n )

Ankie Bosman said...

For me the Hyper-V processor setting did the trick. My Computer is a surface book. Thank you for sharing this solution.

Ariel Machado said...

I'd the same issue with my Surface Pro 4 (Core m3) and solved by changing the Hyper-V setting.

Thank you so much for this good explanation and prevent so many people falling into same problem.

Olegs said...

I did not have that checkbox.
But Hyper-V setting fixed debug issue for me as well! Thanks a lot!

Scott Kuhl said...


Pubudu Gayan said...

Thanks Mate. you saved my day...


try what you said, but did not work in my case, there is another option?

Joost van Schaik said...

@Jose You have the same problem or a different one? Can you provide more information? What emulator are you using, on what version of Windows, and what kind of PC?

Cheryl Van Grinsven said...

Thanks! Great post - a big help!

Ravi said...

try what you said,but did not work for me.I have core i5 processor,4 GB RAM. Emulator has been
launched successfully but application is not deploying.

Output of Visual Studio:

1>------ Build started: Project: Temp_Android, Configuration: Debug Any CPU ------
1> Temp_Android -> C:\Users\sanikumargarg\documents\visual studio 2015\Projects\Temp_Android\Temp_Android\bin\Android\AnyCPU\Debug\Temp_Android.dll
1> Processing: obj\Debug\res\values\strings.xml
1> Processing: obj\Debug\res\values\styles.xml
2>Starting deploy VS Emulator 4" JellyBean (4.2) HDPI Phone ...
2>Starting emulator VS Emulator 4" JellyBean (4.2) HDPI Phone ...
2>Validating emulator arguments...
2>Determining if emulator is already running...
2>Preparing virtual machine...
2>Launching emulator...
2>Emulator launched successfully.

after that i have waited for 30 minutes but not deployed.I have to cancel using ctrl+break.
Is there any other option?

Joost van Schaik said...

Hi @Ravi,

I think the problem you describe is a bit different than the one I offer a solution for here. I describe the problem where the app does deploy but is not debuggable. You, apparently, cannot even deploy.
Steps you might try
* See if you have internet connection sharing on. I have found the Android emulators do not like that upon first start. You can turn in on when the emulator runs succesfully
* Have a look at the in Hyper-V manager and delete virtual machines plus various virtual switches (be careful - if you don't know what you are doing here you can create serious havoc)

Just my $0.05. Good luck

Sunil Rathod said...

Thanks for the article. This helped me solve the problem.