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”

image

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

image

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

image

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.

39 comments:

Unknown 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.

Unknown 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.

Anonymous 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 )

Unknown 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...

THANK YOU!

Anonymous said...

Thanks Mate. you saved my day...

JOSE Y CLAUDIA said...

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?

Unknown 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.

Anonymous said...

Thanks man. Save me a lot of time.

Powers Wartman said...

Thank you! FWIW disabling fast deployment caused me to have a logcat error. I had success leaving that enabled, and only implementing your second step. Either way thanks!

Joe Healy said...

saved my butt. thanks. ever in tampa I owe u a beer.

Joost van Schaik said...

Hi Joe glad I helped you. I don't drink beer (just wine and whisky) and don't see myself getting to Florida in the near future. As far as the USA goes I never got beyond Seattle and it's immediate surroundings. If you meet my friend Richard Hay (the Windows Observer) in Jacksonville buy him a beer by proxy ;)

Anonymous said...

It didn't work for me :( I don't know what else to try. I'm on latest version of VS and Xamarin. Could you help me? Any more ideas?
Thanks

Joost van Schaik said...

Federico - I am afraid I don't. :(

Jeff said...

This link worked for me. Thank you Joost!

Unknown said...

Thank you so much, I've been tearing my hair out trying to fix this for days. I thought it was installing VS2017 that broke it, but it just turns out I hadn't run Xamarin apps since I got this new machine. You are a life saver...

You would think that Microsoft would have fixed this by now and import the emulators with compatibility turned on by default.

Nikola Markezić said...

Only did the processor compatibility and now everything works on my Surface Pro 4, just what I needed, thx

Unknown said...

Thanks thanks thanks!!
For who has the checkbox disabled, make sure that you closed the emulator first.

Unknown said...

I was struggling with this for days. Thank you so much

Unknown said...

Thanks

Otávio said...

Thanks, that works fine!!

jerone said...

More then a year later, this fix still works. Thanks!

Unknown said...

Wuhuuuuuuuu. Tnx man. Where is the button "Buy me a beer" :)

Unknown said...

Thanks! This fix save me a bunch of time!

Unknown said...

Thank you! it worked for me

Ariel Cattaneo said...

Excellent !! Working !!

Unknown said...

Thank you Sir! Saved me a LOT of time! Keep up the good work

Hoeller said...

Great work man! I had wasted a couple of hours already before coming across your post. I usually have to try ten thousand different solutions when I have weird problems like this, but yours worked flawlessly, first attempt and all. Many thanks!

Unknown said...

Hi,
I have the same problem ("Couldn't connect to logcat, GetProcessId returned: 0") debugging with emulator. But I'm using the google emulator (hyper-v is disabled). I already disabled the android options ("Use shared runtime" and "use fast deployment") in my VS2015 but no luck. Any Ideas?
Thx.

Unknown said...

Thanks!
Worked fine for me!
Congrats.