Bug 31519 - Modifying Android resources hangs Visual Studio GUI thread in `JavaProcessConnection.PostMessage()` if the currently installed version of Android SDK Tools is incompatible
Summary: Modifying Android resources hangs Visual Studio GUI thread in `JavaProcessCon...
Status: VERIFIED FIXED
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: Android Designer ()
Version: 3.11 (C5)
Hardware: PC Windows
: Normal major
Target Milestone: 3.11.4 (C5SR4)
Assignee: Bugzilla
URL:
: 16357 18452 23145 30968 ()
Depends on:
Blocks: 31667
  Show dependency tree
 
Reported: 2015-06-30 21:26 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2015-08-27 06:07 UTC (History)
13 users (show)

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


Attachments
Log files, VS minidump, version info (623.54 KB, application/zip)
2015-06-30 21:26 UTC, Brendan Zagaeski (Xamarin Team, assistant)
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 Brendan Zagaeski (Xamarin Team, assistant) 2015-06-30 21:26:58 UTC
Created attachment 11792 [details]
Log files, VS minidump, version info

Modifying Android resources hangs Visual Studio GUI thread if the currently installed version of Android SDK Tools is incompatible




## Regression status: not exactly a regression

This problem has been reported several times before when Google has released other Android tools updates that have broken the designer:

- Bug 16357

- Bug 18452 (Note: The last few comments on this bug suggest that there might be _another_ cause of hangs, at least assuming that at least one of the customers who reported the problem there does in fact have correctly matched Xamarin and Android tools versions, but none of the recent comments on that report mention _both_ the complete Android tools versions and the precise Xamarin version.)

- Bug 23145

- Bug 30968



On the other hand, it is "recently broken again" due to the compatibility-breakage introduced by Google in Android SDK Tools 24.3 [1].

> [1] http://forums.xamarin.com/discussion/42333/requires-xamarin-update-android-sdk-tools-rev-24-3/p1.




## Motivation

The purpose of this bug is to request a better experience for users who might temporarily have mismatched versions of XamarinVS and Android tools. In particular, the workflow of adding and removing resources currently causes Visual Studio to hang in this situation. If possible, one option would be to standardize on the usual outcome in Xamarin Studio on Windows: the mismatch is ignored and the IDE does not hang. Otherwise, perhaps a warning message can be displayed, and then the process that causes the hang can be aborted.


Note: I _was_ able to hit the problem once in Xamarin Studio during various tests of opening and closing "Resource.designer.cs" while also adding and removing "Icon.png", but I found it much easier to reproduce the problem in Visual Studio.




## Version information

Android SDK Tools 24.2
Xamarin   3.11.666.0 (ebae43a)

(These first two versions are the key to the problem. These versions are incompatible: http://forums.xamarin.com/discussion/42333/requires-xamarin-update-android-sdk-tools-rev-24-3/p1.)


Android SDK Platform-tools 22
Android SDK Build-tools 22.0.1

Windows 8.1 (64-bit) in VMWare Fusion 6.0.6 (2684343)




## Steps to reproduce

1. Create a new "Visual C# -> Android -> Blank App (Android)" in Visual Studio.

2. Right-click the "Resources\drawable\Icon.png" file and select "Exclude From Project".

3. Right-click the "drawable" folder to attempt to add back the "Icon.png" file.




## Results

The Visual Studio GUI thread hangs. Attaching a second instance of VS, pausing, and looking at the Main Thread shows the following call stack (excerpt):

> WindowsBase.dll!System.Windows.Threading.DispatcherSynchronizationContext.Wait(System.IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout)
> mscorlib.dll!System.Threading.SynchronizationContext.InvokeWaitMethodHelper(System.Threading.SynchronizationContext syncContext, System.IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout)
> [Native to Managed Transition]	
> mscorlib.dll!System.Threading.WaitHandle.InternalWaitOne(System.Runtime.InteropServices.SafeHandle waitableSafeHandle, long millisecondsTimeout, bool hasThreadAffinity, bool exitContext)
> mscorlib.dll!System.Threading.WaitHandle.WaitOne(int millisecondsTimeout, bool exitContext)
> mscorlib.dll!System.Threading.WaitHandle.WaitOne()
> Xamarin.AndroidDesigner.dll!Xamarin.AndroidDesigner.JavaProcessConnection.PostMessage(Xamarin.AndroidDesigner.BinaryMessage message = {Xamarin.AndroidDesigner.BinaryMessage}, bool checkInitialized)
> Xamarin.AndroidDesigner.dll!Xamarin.AndroidDesigner.JavaProcessConnection.PostMessage(Xamarin.AndroidDesigner.BinaryMessage message)
> Xamarin.AndroidDesigner.dll!Xamarin.AndroidDesigner.DesignerProject.NotifyProjectPathChange(string path, bool isFolder, Xamarin.AndroidDesigner.PathChange change)
> Xamarin.AndroidDesigner.dll!Xamarin.AndroidDesigner.DesignerProject.NotifyProjectFileChange.AnonymousMethod__1b()
> Xamarin.AndroidDesigner.dll!Xamarin.AndroidDesigner.DesignerProject.NotifyResourceDirectoryProcessed()
> Xamarin.VisualStudio.Android.dll!Xamarin.VisualStudio.Android.MonoAndroidFlavoredProject.OnDesignerUpdate(object sender, System.EventArgs e)




## Results in Xamarin Studio 5.9.4 (build 5)

In Xamarin Studio it is almost always possible to add and remove the "Icon.png" file with no hangs even though the Android Designer cannot open any layout files. The "Resource.Designer.cs" file is also updated correctly after each change.

On the other hand, as mentioned earlier, I was somehow able to hit the problem once in Xamarin Studio. As in Visual Studio, in that case the GUI thread was stuck in the call to `AndroidDesigner.JavaProcessConnection.PostMessage()`.




## Workaround: update the Android SDK Tools to version 24.3 or higher.

In the Android SDK Manager, update to Android SDK Tools version 24.3 or higher. This version is required if you have updated to:

- Xamarin for Visual Studio 3.11.586 or higher
- Xamarin Studio 5.9.2.4 or higher




## Alternate workaround

You can in principle edit the resources included by the project by hand-editing the `.csproj` file. Unloading, editing, and reloading the `.csproj` apparently avoids hitting the `AndroidDesigner.JavaProcessConnection.PostMessage()` deadlock.
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2015-06-30 21:45:22 UTC
I am marking all of the older bugs as duplicates of this bug.


1. For any customers coming here from those older bugs, please first confirm that you are either running all of the latest compatible versions:

- Android SDK Tools version 24.3 or higher
- Xamarin for Visual Studio 3.11.586 or higher
- Xamarin Studio 5.9.2.4 or higher


Or all the older compatible versions:

- Android SDK Tools version 24.2 or lower
- Xamarin for Visual Studio 3.11.584 or lower
- Xamarin Studio 5.9.2.2 or lower



2. After you have confirmed that you are running a compatible set of versions, please reply on Bug 30968 with all of the following version information:

- Android SDK Tools
- Android SDK Platform-tools
- Android SDK Build-tools

(See also "Android SDK Tools" on https://kb.xamarin.com/customer/portal/articles/1675684#android-sdk-tools-versions)



3. Please also include your precise Xamarin version information. Ideally if you have Xamarin Studio installed, include all of the information from:

"Help -> About -> Show Details -> Copy Information [button]"


If you only have Visual Studio installed, please instead include the information from:

"Help -> About Microsoft Visual Studio -> Copy Info [button]"



If I see updates with this complete information on Bug 30968, I will un-set the duplicate flag so that that bug will no longer be a duplicate of this bug, and the developers will work on solving that bug _in addition_ to this bug.


Best,
Brendan
Xamarin Customer Support
Comment 3 Brendan Zagaeski (Xamarin Team, assistant) 2015-06-30 21:48:00 UTC
*** Bug 16357 has been marked as a duplicate of this bug. ***
Comment 4 Brendan Zagaeski (Xamarin Team, assistant) 2015-06-30 21:48:22 UTC
*** Bug 18452 has been marked as a duplicate of this bug. ***
Comment 5 Brendan Zagaeski (Xamarin Team, assistant) 2015-06-30 21:48:48 UTC
*** Bug 23145 has been marked as a duplicate of this bug. ***
Comment 6 Brendan Zagaeski (Xamarin Team, assistant) 2015-06-30 21:49:47 UTC
*** Bug 30968 has been marked as a duplicate of this bug. ***
Comment 7 Brendan Zagaeski (Xamarin Team, assistant) 2015-07-06 13:16:36 UTC
Update: there is no longer a need to add reports on Bug 30968.

There is instead now a new Bug 31667 for hangs seen with Android SDK Tools 24.3 or higher + XamarinVS 3.11.586 or higher. It is not yet clear what additional environmental factors are required to reproduce a hang in that case. One piece of information that might help on that bug would be a minidump (_without_ heap) from the hung instance of VS, so if anyone can reproduce that hang, feel free to attach a minidump to Bug 31667.
Comment 8 Udham Singh 2015-07-08 09:44:32 UTC
I have checked this issue with the help of test steps given in bug description and able to reproduce this issue. 

Screencast : http://www.screencast.com/t/fuDk6mhkccMV
Xamarin VS Logs : https://gist.github.com/Udham1/2062da84d7f1bf118880

Environment Info : https://gist.github.com/Udham1/813d9ccdfa614759ae34
Comment 9 PJ 2015-07-13 12:37:13 UTC
Missed freeze deadline for C5SR3, updating milestone.
Comment 12 Brendan Zagaeski (Xamarin Team, assistant) 2015-08-06 21:55:58 UTC
I checked the behavior of this bug quickly today on a XamarinVS build from master, and I can verify that it stops the problem.

## Version info (brief)

Android SDK Tools 24.2

XamarinVS 5.1.323.0 (7984c9e)
Comment 14 Mahmood 2015-08-10 12:49:17 UTC
I am experiencing the same issues but I manage to delete by using the following
steps:

step 1: Unload the project
step 2: comment out or delete the resource file that you want to get rid of
step 3: Delete the file(resource item) from the explorer
step 4: Reload the project

Hope it will solve the problem
Comment 15 Mahmood 2015-08-11 09:37:49 UTC
I am experiencing the same issues but I manage to delete by using the following
steps:

step 1: Unload the project
step 2: comment out or delete the resource file that you want to get rid of
step 3: Delete the file(resource item) from the explorer
step 4: Reload the project

Hope it will solve the problem
Comment 16 Abhishek 2015-08-11 13:36:16 UTC
I have checked this issue with XVS 3.11.666. I am successfully able to reproduce this issue at my end.

To verify this issue.I have checked this issue with latest C5 Trunk build
Xamarin.VisualStudio_3.11.857_ec6caef52368012ea25e827d6df5c13db7f6eed3. Now this issue is working fine.Here is the screencast for the same:
http://www.screencast.com/t/8FIxxvOK

Hence closing this issue.
Comment 17 Alan McGovern 2015-08-21 11:17:51 UTC
*** Bug 33270 has been marked as a duplicate of this bug. ***
Comment 18 Alan McGovern 2015-08-21 12:29:56 UTC
As per comment 10, this is fixed only in master and not in cycle 5. It is expected that cycle 5 hangs.
Comment 19 Abhishek 2015-08-24 15:18:11 UTC
I have checked this issue with latest C5SR4 build Xamarin.VisualStudio_3.11.890_c2ca9ac2c832f09893afd1643d72e9360eec7d0b and I observed the same issue with latest SDK Tool 24.3.4.

However this issue is working fine with Master build 
Xamarin.VisualStudio_4.0.0.991_842355dd752251619846d451ac99fbc903b1308f.
Here is the screencast for the same: http://www.screencast.com/t/6XsHhZj4

As of now I am reopening this issue against C5SR4 build.

Thanks.
Comment 20 Alan McGovern 2015-08-25 16:23:24 UTC
*** Bug 32845 has been marked as a duplicate of this bug. ***
Comment 21 nickelnext 2015-08-26 05:23:09 UTC
I'm posting what i have 

Microsoft Visual Studio Enterprise 2015
Versione 14.0.23107.0 D14REL
Microsoft .NET Framework
Versione 4.6.00081

Edizione installata: Enterprise

Architecture and Modeling Tools   00322-80000-00000-AA671
Microsoft Architecture and Modeling Tools
    
UML® e Unified Modeling Language™ sono marchi o marchi registrati di Object Management Group, Inc. negli Stati Uniti e in altri paesi.

Visual Basic 2015   00322-80000-00000-AA671
Microsoft Visual Basic 2015

Visual C# 2015   00322-80000-00000-AA671
Microsoft Visual C# 2015

Visual C++ 2015   00322-80000-00000-AA671
Microsoft Visual C++ 2015

Windows Phone SDK 8.0 - ITA   00322-80000-00000-AA671
Windows Phone SDK 8.0 - ITA

ASP.NET e strumenti Web   14.0.20626.0
ASP.NET e strumenti Web

ASP.NET Web Frameworks and Tools 2013   5.2.30624.0
For additional information, visit http://www.asp.net/

Genera unit test   1.0
Genera il codice degli unit test per i metodi nelle classi sottoposte a test.

Gestione pacchetti NuGet   3.0.0
Gestione pacchetti NuGet in Visual Studio. Per altre informazioni su NuGet, visitare il sito Web http://docs.nuget.org/.

GitHub.VisualStudio   1.0
A Visual Studio Extension that brings the GitHub Flow into Visual Studio.

Microsoft Code Digger   0.9
Microsoft Code Digger

Microsoft.Pex.VisualStudio   1.0
Pex

Pacchetto di Strumenti Application Insights per Visual Studio   1.0
Strumenti Application Insights per Visual Studio

SQL Server Data Tools   14.0.50616.0
Microsoft SQL Server Data Tools

Strumenti comuni di Azure   1.5
Fornisce servizi comuni da usare con Servizi mobili di Azure e gli strumenti di Microsoft Azure.

Strumenti di Servizi Mobili di Microsoft Azure   1.4
Strumenti di Servizi Mobili di Microsoft Azure

Visualizzatore PreEmptive Analytics   1.2
Estensione di Microsoft Visual Studio per visualizzare i riepiloghi aggregati dal prodotto PreEmptive Analytics.

Xamarin   3.11.837.0 (f10676f)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   5.1.5.3 (f98871a95a479f6d71b3067b7e5834d41fcb2118)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   8.10.4.0 (6db87c53c073f4af2f5247fb738a27ea08c094fd)
Visual Studio extension to enable development for Xamarin.iOS.

Xamarin.iOS Unified Migration   1.0
Automated migration for Xamarin iOS Classic projects to Unified

Xamarin.TestCloud.Integration   1.0
Early preview of Xamarin Test Cloud integration

in the sdk manager i have downloaded and installed API up until 23, and all the android sdk tools (from 19.1 to 24.3) with also platform-tools 23

Still, when including files in a project in VS (both 2013 and 2015) it crashes.
Can't find the way to fix this
Comment 23 Alan McGovern 2015-08-26 16:05:58 UTC
joj could reproduce the bug when he was using an older version of the code. When he rebuilt with latest commit in the c5sr4 branch the bug went away.  That means that the backported commit did fix the issue for him ( https://github.com/xamarin/md-addins/commit/d572510df6c395d3c7fae2b3bdd93b0340ed1334 ).

Comment 19 says that VS deadlocked when android sdk tools 24.3.4 was installed. If that is happening then the hang is not the one described in this bug, it is something else. This bug can only happen if an obsolete version of the android sdk tools is installed and the patch linked above is not in place.

As i cannot reproduce the bug with the latest builds and joj also confirmed that the latest builds fix the hang for him, i'm going to close this bug.

In order to verify the fix remember that you need to install an android sdk tools *older* than 24.3.4.

If you can reproduce a hang with android sdk tools 24.3.4 installed, then please file a new bug with the repro steps so we can investigate.
Comment 24 Abhishek 2015-08-27 06:07:05 UTC
I have checked this issue as per comment 23 with the latest C5SR4 build Xamarin.VisualStudio_3.11.893_dd3b11439ca3da4c5acee177a563305abd62ef33. Now this issue is working fine with older SDK 24.3.3 and VS does not hang.

Here is the screencast for same: http://www.screencast.com/t/U8HI9PT2Wn
Designer would not open as it give proper error message to update sdk tool to 24.3.4.

screencast for SDK: http://www.screencast.com/t/TLMmxAi3V 

Hence closing this issue.

I have already filed the bug #33270 against newer SDK 24.3.4. I am reopening this bug.