Bug 34676 - Breakpoints do not trigger in an async RelayCommand
Summary: Breakpoints do not trigger in an async RelayCommand
Status: VERIFIED FIXED
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: Debugger ()
Version: 4.0.0 (C6)
Hardware: PC Windows
: High normal
Target Milestone: 4.0.0 (C6)
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-10-08 04:56 UTC by NMackay
Modified: 2016-05-10 17:05 UTC (History)
9 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
XVS log files for 4.0.0.1668 verification (23.13 KB, application/octet-stream)
2015-11-06 17:32 UTC, Ben Beckley
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 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 NMackay 2015-10-08 04:56:40 UTC
Async methods do not debug at all in PCL projects.

The following code does not trigger a breakpoint on the Busy flag set:

public RelayCommand PerformanceCommand
        {
            get
            {
                return _prefCommand
                       ?? (_prefCommand = new RelayCommand(
                           async () =>
                           {
                               try
                               {
                                   Busy = true; << breakpoint here does not trigger

                                   // Check if already navigated to avoid multiple taps on the handset
                                   if (_navService.CurrentPageKey == ViewModelLocator.PageKeyVesPerf) return;
                                   await _navService.NavigateTo(ViewModelLocator.PageKeyVesPerf, SelectedVessel);
                               }
                               catch (Exception ex)
                               {
                                   _exService.Error(GetType().Name, ex);
                               }
                               Busy = false;
                           },
                           () => !_busy));
            } << breakpoint triggers here on page load
        }

Instead the breakpoint triggers at the end of the get when the page is instantiated.

Essentially it is impossible to debug an Forms PCL MVVM app when using async (which in my case is 80%+ of the code).
Comment 1 NMackay 2015-10-08 04:59:26 UTC
Also cleaning the solution and deleting ob and bin folders in all projects and rebuilding makes no difference.
Comment 3 Arpit Jha 2015-10-09 06:36:47 UTC
I have checked this issue with Xamarin.Forms.1.5.0.6447 and able to reproduce this issue with the help of attached project in https://bugzilla.xamarin.com/show_bug.cgi?id=34676#c2.

OBservation: I observed that breakpoints do not hit in an async RelayCommand with iOS debugger in xamarin.Forms.

However I checked the same with android debugger and observed that breakpoints gets hits.

Screencast: 
Android : http://www.screencast.com/t/KwkYusmMQxUI
iOS : http://www.screencast.com/t/XzEvrupH
IDE log: https://gist.github.com/Arpit360/6917caf48e9d7774c78b

Environment Info:
[ Xamarin.Forms.1.5.0.6447]
Microsoft Visual Studio Professional 2013
Version 12.0.40629.00 Update 5
Microsoft .NET Framework
Version 4.5.51641

Installed Version: Professional

Windows Phone 8.1 SDK Integration   1.0
This package integrates the tools for the Windows Phone 8.1 SDK into the menus and controls of Visual Studio.

Workflow Manager Tools 1.0   1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin   4.0.0.1571 (22caadd)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   6.0.0.11 (f94dc5b)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   9.2.0.85 (7bcf0da)
Visual Studio extension to enable development for Xamarin.iOS.
Comment 7 Rolf Bjarne Kvinge [MSFT] 2015-10-22 10:05:58 UTC
@Jares, so everything works as expected if the linker is disabled?
Comment 8 Joaquin Jares 2015-10-22 10:59:50 UTC
I need to verify it with this bug. With others that were identical, it worked with linker disabled.
Comment 9 NMackay 2015-10-22 11:15:15 UTC
I'm still using the candidate release on a daily basis due to much better performance in both Android and iOS. I have observed the same behavior debugging in Android sometimes.
Comment 10 Joaquin Jares 2015-10-22 12:51:28 UTC
I have just verified with no linker and the behavior is the same, so my initial estimate seems off. I'm dumping mdb right now to see if lines match what I expect them to be there.
Comment 11 Joaquin Jares 2015-10-22 13:19:45 UTC
All the relevant information is here: https://gist.github.com/joj/3baed9d4a32a05cab0b7

What I'm seeing is that the breakpoint is set in the correct location (in debugger output) but then the line number on the call stack when the breakpoint is actually hit is wrong. 

Proving path for the dlls look off, though. I need to verify that.
Comment 12 Joaquin Jares 2015-10-22 13:22:05 UTC
Doesn't look like a iOS/runtime bug, but a second-level PCL bug. Trying a fix.
Comment 13 Joaquin Jares 2015-10-26 11:56:28 UTC
I have created PR#4411 to address the mdb generation for second-level PCL, but I'm still observing the bug. We need runtime support at this point.
Comment 14 philip 2015-10-28 14:11:04 UTC
This happens with Android debugging as well:


Device.BeginInvokeOnMainThread(
	async () =>
	{
             // breakpoints inside here do not work properly.  They seem to hit somewhere outside the lambda.
        }
Comment 18 dean.ellis 2015-11-03 09:23:40 UTC
This is definitely a 2nd level PCL issue. Referencing the .Data project from the main android app allows the .mdb to be generated and the debugging works.
Comment 19 xamarin-release-manager 2015-11-03 12:17:08 UTC
Fixed in version 99.0.0.542 (master)

Author: Jose Gallardo
Commit: 176dbdecd00a42e84899b06df7b5f13ff4611c08 (xamarin/XamarinVS)
Comment 20 Joaquin Jares 2015-11-04 07:36:13 UTC
I have pushed a change made by Dean to our targets that should also fix this for Android.
Comment 21 Ben Beckley 2015-11-06 17:32:32 UTC
Created attachment 13711 [details]
XVS log files for 4.0.0.1668 verification

Hello all, I have verified that the fix for the x.iOS issue using the attached project and following the reproduction steps. This was using build 4.0.0.1668 (a6bf8166) from the xvs-win-cycle6-34676 branch and XI 9.2.1.38 on the build host.

In addition to following the reproduction steps, I used a freshly unzipped project and added the PCL projects to be built in the Solution Configuration.

screencast:
http://www.screencast.com/users/benbeckley/folders/Jing/media/f92fd622-bf59-44d9-bbb1-b1c4e3a19f2d

system environment:
https://gist.github.com/BenBeckley/4db96934c0fceb6d5a6c

I've also attached the logs from this session.



Also before testing this, I ensured that I was able to reproduce the issue using a build without the fix. This was using build 4.0.0.1571 (22caadd) from the xvs-win-cycle6 branch and XI 9.2.0.85 on the build host.

In accordance with the other session, this was with a fresh unzip and included the PCL projects in the Solution Configuration.

screencast:
http://www.screencast.com/users/benbeckley/folders/Jing/media/a99cd7b5-7849-4e37-ab80-884ca2aebf55

system environment:
https://gist.github.com/BenBeckley/b8a7139e1824e82f7dc0


I also tried to reproduce this using the current stable XVS 3.11.1589 but was unable to hit any breakpoints.
Comment 22 Joaquin Jares 2015-11-09 07:41:06 UTC
Per c#21, marking this as verified.
Comment 23 xamarin-release-manager 2015-11-26 10:39:40 UTC
Fixed in version 4.0.1.1 (cycle6)

Author: Jose Gallardo
Commit: 7f653bc081175322a49c6382c691a4f221f861a2 (xamarin/XamarinVS)