Bug 39433 - "System.NullReferenceException: Object reference not set to an instance of an object" at AD7Events.cs line 433 thrown by the IDE extension when processing AD7DebugExceptionEvent debugger events from the Android application
Summary: "System.NullReferenceException: Object reference not set to an instance of an...
Status: RESOLVED FIXED
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: Debugger (show other bugs)
Version: 4.0.0 (C6)
Hardware: PC Windows
: Normal major
Target Milestone: 4.0.4 (C6SR4)
Assignee: Bugzilla
URL:
: 38122 38282 38894 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-03-08 03:26 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2016-05-17 12:37 UTC (History)
15 users (show)

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

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:
RESOLVED FIXED

Description Brendan Zagaeski (Xamarin Team, assistant) 2016-03-08 03:26:54 UTC
"System.NullReferenceException: Object reference not set to an instance of an object" at AD7Events.cs line 433 thrown by the IDE extension when processing AD7DebugExceptionEvent debugger events from the Android application




## Regression status: suspected regression in Cycle 6

(I will post additional details from individual customer reports in follow-up comments.)




## Results

The debugger connection in Visual Studio throws a null reference exception. This is presented to the user via a Visual Studio alert dialog.

> Exception in OnUnhandledException:
> System.NullReferenceException: Object reference not set to an instance of an object
> at Xamarin.VisualStudio.Debugger.AD7DebugExceptionEvent..ctor(Thread thread, String description) in C:\Users\builder\data\lanes\2853\dcea9c13\source\XamarinVS\src\Core\VisualStudio\Debugging\MonoTools.Engine\AD7Events.cs:line 433
> at Xamarin.VisualStudio.Debugger.ExceptionsAdapter.OnExceptionThrown(Object sender, TargetEventArgs args) in C:\Users\builder\data\lanes\2853\dcea9c13\source\XamarinVS\src\Core\VisualStudio\Debugging\MonoTools.Engine\ExceptionsAdapter.cs:line 42


(Since the exception is producing a VS alert dialog, I expect it is being thrown on Visual Studio's main GUI thread.)




## Steps to replicate

No local steps have so far been found to replicate the problem locally on any Xamarin employee's computer.




## Clues about the conditions needed to replicate the problem


- This problem most likely won't happen unless the app being debugged throws some exceptions (since the problem seems to be related to processing exceptions that are thrown by the app).


- It seems the problem might be related to the state of the Visual Studio environment:

> I started getting this every time... I still get these null refs, when
> it happens, I am forced to restart VS to stop them - for a while, and
> then they appear again.
(Bug 38282)


- It might be easier to replicate the problem:

(a) If the Android app performs some longer-running tasks during the initialization of a new activity:

> the problem was that my application took to long to execute hes task
> so i wrapped it up on a background task
In that case the last message from the adb log before the error was:
> Timeline: Activity_launch_request
(https://stackoverflow.com/questions/35011940/xamarin-strange-exception-in-vs2015)


(b) If the Android app attempts to communicate with Bluetooth LE devices:

> I'm Developing an APP wich communicate with BLE devices... when i
> switch multiple times from an activity i get an undebuggable
> exception
(Bug 38122)




## Possible test cases

- We have a full customer project in the non-public support case https://kb.xamarin.com/agent/case/295699, but the Support Team has so far not been able to replicate the problem using that test case.
Comment 3 Brendan Zagaeski (Xamarin Team, assistant) 2016-03-08 03:46:51 UTC
## Update: I was able to replicate the problem locally

> We have a full customer project in the non-public support case
> https://kb.xamarin.com/agent/case/295699, but the Support Team has so far not
> been able to replicate the problem using that test case.
(Comment 0)

I have now been able to replicate the problem locally at least once using that test case. I will investigate a bit more to make sure I can replicate the problem consistently and then post another update with the steps to replicate.
Comment 4 Brendan Zagaeski (Xamarin Team, assistant) 2016-03-08 03:56:47 UTC
*** Bug 38282 has been marked as a duplicate of this bug. ***
Comment 5 Brendan Zagaeski (Xamarin Team, assistant) 2016-03-08 03:59:50 UTC
*** Bug 38122 has been marked as a duplicate of this bug. ***
Comment 7 Brendan Zagaeski (Xamarin Team, assistant) 2016-03-08 16:54:16 UTC
## Update: this bug might have the same underlying cause as Bug 36078

See Bug 36078, Comment 17 for a link to a build that includes a candidate fix. The underlying issue in both cases appears to be that the soft debugger was incorrectly caching thread descriptors, leading to incorrect null references to the threads in some situations.




## My next steps

I will test the candidate build from Bug 36078, Comment 17 using the test case mentioned in Comment 3 to attempt to verify that the bug as demonstrated by that test case is indeed fixed by the candidate build.
Comment 8 Brendan Zagaeski (Xamarin Team, assistant) 2016-03-08 18:37:58 UTC
## One preliminary customer verification

The original customer on non-public support case https://kb.xamarin.com/agent/case/295699 has verified that the candidate build from Bug 36078, Comment 17 has stopped the problem for them locally.

I will accordingly tentatively mark the bug as RESOLVED FIXED, awaiting additional customer verifications.




## Candidate fix

I will copy the information about the candidate build directly into this bug report for easier reference.

This is a version of 4.0.1.145 ("Cycle 6 – Service Release 2") plus the candidate fix:
http://xvs.xamarin.com/patcheddrops/Xamarin.VisualStudio_4.0.1.146.msi

As always, this version is completely untested and should be used at your own risk. You can always revert to .145 if it doesn't work for you.




## Additional customer verifications encouraged

Since the Xamarin team does not have an easy way to replicate this exact problem (see also my note below about my canceled attempt at verification), additional customer verifications of the bug would be helpful.

If any other users can verify that they no longer hit this problem after updating to the candidate build 4.0.1.146, feel free to leave a quick comment on this bug report to mention that the candidate build did solve the problem for you. Thanks!




## Cancellation of my independent verification attempt

In my further testing I was able to replicate the problem several times with the test case from Comment 3, but the behavior was not consistent, so I would not be able to verify the fix with much certainty. Multiple independent customer verifications will be better.
Comment 9 Brendan Zagaeski (Xamarin Team, assistant) 2016-03-08 19:05:46 UTC
## Additional details about the candidate fix, for reference

As I understand it, the candidate fix is precisely the following commit:
https://github.com/mono/debugger-libs/commit/1c9da99677617436279df20d37bb47b197fdd374

(Which was merged from https://github.com/mono/debugger-libs/pull/71)
Comment 10 Brendan Zagaeski (Xamarin Team, assistant) 2016-03-08 19:20:59 UTC
*** Bug 38894 has been marked as a duplicate of this bug. ***
Comment 11 Markus 2016-03-10 09:16:16 UTC
I have just tested the bugfix, and it works for me!! You were right, there were exceptions flying in my Code, which I now see again.  

Thank you Brendan (and all others)!
Comment 12 Torleif Sandnes 2016-03-11 07:16:33 UTC
This bugfix solved the problem for me as well.

In addition, the threads view in visual studio also works when debugging iOS applications.

Thanks!
Comment 13 Jim Bennett 2016-03-16 21:35:58 UTC
We were having endless problems here with our app just randomly crashing when a handled exception was thrown.  After installing this the random crashes have gone away and we're suddenly a lot more productive!

When will this be pushed to the offical stable release?  We keep getting 'upgrade' notifications to install the 145 build.
Comment 14 Malcolm Jack 2016-03-30 14:25:49 UTC
Also experiencing this on build 147. Looking forward to an official fix
Comment 15 Dimitar Dobrev 2016-04-11 09:17:10 UTC
There's a new release at https://releases.xamarin.com/stable-release-cycle-6-service-release-3/, does it contain this fix?
Comment 16 Markus 2016-04-11 14:48:38 UTC
The fix is _not_ in the current release. Could please someone merge this back in release. 

Please!!
Comment 17 Brendan Zagaeski (Xamarin Team, assistant) 2016-05-03 17:10:01 UTC
In case any other users have the same question as Comment 15 or Comment 16, the target milestone for the bug has now (as of April 17) been set to "4.0.4 (C6SR4)". "(C6SR4)" stands for "Cycle 6 – Service Release 4". You can watch https://releases.xamarin.com/ for news about the release of "Cycle 6 – Service Release 4". The tentative plan at the moment is to release that version within a week or so.

Note that the fix is also included in the current Beta ("Cycle 7") and Alpha ("Cycle 8") channel [1] versions, and both of those versions do also include the new licensing changes.

[1] https://developer.xamarin.com/recipes/cross-platform/ide/change_updates_channel/
Comment 18 Markus 2016-05-03 17:20:20 UTC
Thanks Brendan!