Bug 56238 - [15.2] Could not connect to debugger, app exits on launch, or breakpoints skipped when Optimize property is not explicitly set to False
Summary: [15.2] Could not connect to debugger, app exits on launch, or breakpoints ski...
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Debugger (show other bugs)
Version: 7.3 (15.2)
Hardware: PC Windows
: --- normal
Target Milestone: 15.2.2
Assignee: Bugzilla
URL:
: 56755 (view as bug list)
Depends on:
Blocks: 56225
  Show dependency tree
 
Reported: 2017-05-11 17:48 UTC by Matt Perzel
Modified: 2017-05-23 15:26 UTC (History)
8 users (show)

Tags: 15.2R
Is this bug a regression?: Yes
Last known good build: Xamarin.Android 7.2


Attachments
Output Logs (73.45 KB, text/plain)
2017-05-19 13:17 UTC, Alok Kulkarni
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description Matt Perzel 2017-05-11 17:48:28 UTC
After updating to latest VS 2017(15.2 26430.4) on May 10, 2017 we can no longer connect with the debugger on multiple different machines. Can not connect to the x86 HAXM emulator or a hardware device. 

*We receive the following output:*

Android application is debugging.
05-11 10:26:12.303 W/monodroid(13457): Trying to load sgen from: /data/app/com.microsoft.msn.news-1/lib/arm64/libmonosgen-2.0.so
05-11 10:26:12.303 W/monodroid(13457): Trying to load sgen from: /data/user/0/com.microsoft.msn.news/files/.__override__/links/libmonosgen-2.0.so
05-11 10:26:12.305 W/monodroid-debug(13457): Trying to initialize the debugger with options: --debugger-agent=transport=dt_socket,loglevel=0,address=127.0.0.1:8883,server=y,embedding=1
05-11 10:26:12.305 W/monodroid-debug(13457): Accepted stdout connection: -1
05-11 10:26:12.305 F/monodroid-debug(13457): Error accepting stdout and stderr (127.0.0.1:8884): Address already in use
Could not connect to the debugger.


*Visual Studio Info*

Microsoft Visual Studio Enterprise 2017 
Version 15.2 (26430.4) Release
VisualStudio.15.Release/15.2.0+26430.4
Microsoft .NET Framework
Version 4.7.02046

Installed Version: Enterprise

Visual Basic 2017   00369-60000-00001-AA238
Microsoft Visual Basic 2017

Visual C# 2017   00369-60000-00001-AA238
Microsoft Visual C# 2017

Visual C++ 2017   00369-60000-00001-AA238
Microsoft Visual C++ 2017

Visual F# 4.1   00369-60000-00001-AA238
Microsoft Visual F# 4.1

Application Insights Tools for Visual Studio Package   8.6.00404.2
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017   15.0.30503.0
ASP.NET and Web Tools 2017

Common Azure Tools   1.9
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

JavaScript Language Service   2.0
JavaScript Language Service

JavaScript Project System   2.0
JavaScript Project System

JavaScript UWP Project System   2.0
JavaScript UWP Project System

Merq   1.1.17-rc (cba4571)
Command Bus, Event Stream and Async Manager for Visual Studio extensions.

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio   Mono.Debugging.VisualStudio
Support for debugging Mono processes with Visual Studio.

NuGet Package Manager   4.2.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

ProductNameID   1.0
ProductDescriptionID

TypeScript   2.2.2.0
TypeScript tools for Visual Studio

Visual Studio Tools for Universal Windows Apps   15.0.26430.01
The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

VSColorOutput   2.5
Color output for build and debug windows - http://mike-ward.net/vscoloroutput

VsVim   2.3.0.0
VsVim is a Vim emulator for Visual Studio

Xamarin   4.5.0.443 (c871575)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android SDK   7.3.0.13 (448f54f)
Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK   10.10.0.30 (30b6e87)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
Comment 1 Joaquin Jares 2017-05-12 17:44:12 UTC
I moved the port range to a IANA unassigned segment to avoid collitions.
Comment 3 Joaquin Jares 2017-05-15 17:58:37 UTC
Changing ports didn't help. Reopening.
Comment 4 Jonathan Pryor 2017-05-15 18:11:33 UTC
Note: Comment #1 and Comment #2 are incorrect.

Scenario: Xamarin.Android project in which `$(Optimize)` is not set
for the Debug configuration. Load project within VS 2017 and attempt
to debug.

Result: app crashes on startup, debugger cannot connect.

`adb logcat` contains:

        F monodroid: No assemblies found in '(null)' or '<unavailable>'.  Assuming this is part of Fast Deployment. Exiting...

What's happening is that the Debug configuration app was bundling the
*Release* `libmonodroid.so`, as verified by comparing file sizes; the
deployed `libmonodroid.so` was 161244 bytes, which is the same as the
installed `libmono-android.release.so` file.

Why was a Debug configuration deployment using the Release runtime?
Because of [xamarin-android/1e0e0834][0], which migrated
`Xamarin.Android.Common.targets` to use `$(Optimize)` instead of the
kludge of other properties which was used previously. Commit 1e0e0834
was comparing `$(Optimize)` against False, but many existing projects
don't set `$(Optimize)` for the Debug Configuration *at all*, meaning
it was comparing the empty string to `False`, which failed, which
prompted `<BuildApk/>` to behave as if the Release runtime were
requested, which was *not* the case here.

Bump to xamarin-android/fd86ab04 which corrects the `$(Optimize)`
comparison, which will allow Debug deployment to work as intended.

Fixed in:
https://github.com/xamarin/xamarin-android/commit/fd86ab04e66c8578c49f687650b2a4e5a477f832
monodroid/d15-2/c7132f35

[0]: https://github.com/xamarin/xamarin-android/commit/1e0e0834
Comment 5 Matt Perzel 2017-05-15 18:36:42 UTC
I can confirm that adding the following to the debug configuration of my csproj fixed this issue.

<Optimize>false</Optimize>
Comment 6 Brendan Zagaeski (Xamarin Team, assistant) 2017-05-15 23:16:41 UTC
## Bookkeeping note

Cross-reference to related developercommunity item:
https://developercommunity.visualstudio.com/content/problem/49033/cannot-debug-xamarinandroid-app-debuggerapp-immedi.html
Comment 9 Gaurav Ganorkar 2017-05-17 09:26:39 UTC
Verified this issue on the build VS 2017
4.5.0.458 and 4.5.0.463

Gist info- https://gist.github.com/mohakbarokar/8a88dab84786b327cdab71828d718a80
ScreenCast link -https://www.screencast.com/t/vcoxPy6x5

Have verified the scenario 
1-Created an Xamarin Forms app (PCL & Shared)/Andorid single view app , and Verified debugger is getting hit.
2-Also verified after creating any Xamarin.forms project , the default values is set as  <Optimize>false</Optimize> in csproj.

Hence marking this issue as verified and Fixed.
Comment 10 Gaurav Ganorkar 2017-05-17 09:29:09 UTC
Verified this issue on the build VS 2017
4.5.0.458 and 4.5.0.463

Gist info- https://gist.github.com/mohakbarokar/8a88dab84786b327cdab71828d718a80
ScreenCast link -https://www.screencast.com/t/vcoxPy6x5

Have verified the scenario 
1-Created an Xamarin Forms app (PCL & Shared)/Andorid single view app , and Verified debugger is getting hit.
2-Also verified after creating any Xamarin.forms project , the default values is set as  <Optimize>false</Optimize> in csproj.

Hence marking this issue as verified and Fixed.
Comment 11 Brendan Zagaeski (Xamarin Team, assistant) 2017-05-17 15:45:47 UTC
The verification attempts in Comment 9 and Comment 10 would not cover the scenario described in this bug report.

To test the scenario described in this bug report, it would be necessary to attempt debugging in a project configuration where the `<Optimize>` settings is _not present at all_.  The publicly viewable commit in Comment 4 is not a change in the template projects, but a change in the build logic.
Comment 12 Alok Kulkarni 2017-05-19 13:17:38 UTC
Created attachment 22311 [details]
Output Logs

Verified on VS2017 Build Xamarin 4.5.0.471

Build Info : https://gist.github.com/p-lad/2a0eefa3fcd53353e8b216e892d7bd37

Output logs attached.

Marking Verified Fixed.
Comment 13 Greg Munn 2017-05-23 15:26:12 UTC
*** Bug 56755 has been marked as a duplicate of this bug. ***