Bug 59553 - Debug fails: An item with the same key has already been added.
Summary: Debug fails: An item with the same key has already been added.
Status: CONFIRMED
Alias: None
Product: Android
Classification: Xamarin
Component: Debugger ()
Version: 7.4 (15.3)
Hardware: PC Windows
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-09-18 12:02 UTC by Daniel Vaughan
Modified: 2017-09-20 15:55 UTC (History)
2 users (show)

Tags:
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 for Bug 59553 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Daniel Vaughan 2017-09-18 12:02:39 UTC
Debugging my Xamarin Android app fails intermittently with the error message:
An item with the same key has already been added.

This is Visual Studio. The verbose output in the output window shows:

1>100% ... 8785kb of 8785kb copied
1>TASK: Push bin\IDebug\com.outcoder.ibrowser-Signed.apk : /data/local/tmp/com.outcoder.ibrowser-Signed.apk completed?:Completed
1>DEBUG RunShellCommand emulator-5554 pm install "/data/local/tmp/com.outcoder.ibrowser-Signed.apk"
1>TASK: UninstallPackage pm uninstall -k "com.outcoder.ibrowser" completed?:Success
1>
1>TASK: InstallPackage pm install "/data/local/tmp/com.outcoder.ibrowser-Signed.apk" completed?:	pkg: /data/local/tmp/com.outcoder.ibrowser-Signed.apk
1>Success
1>
1>DEBUG RunShellCommand emulator-5554 rm "/data/local/tmp/com.outcoder.ibrowser-Signed.apk"
1>TASK: DeleteFile rm "/data/local/tmp/com.outcoder.ibrowser-Signed.apk" completed?:
1>[END] 
1>[MESSAGE] Getting installation path...
1>Getting installation path...
1>DEBUG RunShellCommand emulator-5554 "pm" "path" "com.outcoder.ibrowser"
1>DEBUG RunShellCommand emulator-5554 "echo" "-n" "${EMULATED_STORAGE_SOURCE}"
1>DEBUG RunShellCommand emulator-5554 "echo" "-n" "${EMULATED_STORAGE_TARGET}"
1>DEBUG RunShellCommand emulator-5554 am broadcast -a "mono.android.intent.action.EXTERNAL_STORAGE_DIRECTORY" -n "Mono.Android.DebugRuntime/com.xamarin.mono.android.ExternalStorageDirectory"
1>TASK: Broadcast am broadcast -a "mono.android.intent.action.EXTERNAL_STORAGE_DIRECTORY" -n "Mono.Android.DebugRuntime/com.xamarin.mono.android.ExternalStorageDirectory" completed?:Broadcasting: Intent { act=mono.android.intent.action.EXTERNAL_STORAGE_DIRECTORY cmp=Mono.Android.De...
1>[MESSAGE] Using fast dev path: /storage/emulated/0/Android/data/com.outcoder.ibrowser/files/.__override__
1>Using fast dev path: /storage/emulated/0/Android/data/com.outcoder.ibrowser/files/.__override__
1>[MESSAGE] Fast dev didn't succeed, trying another location...
1>[MESSAGE] Getting installation path...
1>Fast dev didn't succeed, trying another location...
1>Getting installation path...
1>DEBUG RunShellCommand emulator-5554 "pm" "path" "com.outcoder.ibrowser"
1>[MESSAGE] Using fast dev path: /data/data/com.outcoder.ibrowser/files/.__override__
1>Using fast dev path: /data/data/com.outcoder.ibrowser/files/.__override__
1> Deployment failed
1>System.ArgumentException: An item with the same key has already been added.
1>   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
1>   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
1>   at Mono.AndroidTools.Adb.AdbSyncDirectory.Add(AdbSyncItem entry) in C:\d\lanes\4985\0841c2aa\source\xamarinvs\External\md-addins\MonoDevelop.MonoDroid\external\androidtools\Mono.AndroidTools\Adb\AdbSyncDirectory.cs:line 66
1>   at Xamarin.AndroidTools.AndroidDeploySession.<InstallAssemblies>d__112.MoveNext() in C:\d\lanes\4985\0841c2aa\source\xamarinvs\External\md-addins\MonoDevelop.MonoDroid\external\androidtools\Xamarin.AndroidTools\Sessions\AndroidDeploySession.cs:line 515
1>--- End of stack trace from previous location where exception was thrown ---
1>   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
1>   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1>   at Xamarin.AndroidTools.AndroidDeploySession.<FastDevAsync>d__109.MoveNext() in C:\d\lanes\4985\0841c2aa\source\xamarinvs\External\md-addins\MonoDevelop.MonoDroid\external\androidtools\Xamarin.AndroidTools\Sessions\AndroidDeploySession.cs:line 455
1>--- End of stack trace from previous location where exception was thrown ---
1>   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
1>   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1>   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
1>   at Xamarin.AndroidTools.AndroidDeploySession.<RunAsync>d__101.MoveNext() in C:\d\lanes\4985\0841c2aa\source\xamarinvs\External\md-addins\MonoDevelop.MonoDroid\external\androidtools\Xamarin.AndroidTools\Sessions\AndroidDeploySession.cs:line 219
1>--- End of stack trace from previous location where exception was thrown ---
1>   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
1>   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
1>   at Xamarin.AndroidTools.AndroidDeploySession.<RunLoggedAsync>d__99.MoveNext() in C:\d\lanes\4985\0841c2aa\source\xamarinvs\External\md-addins\MonoDevelop.MonoDroid\external\androidtools\Xamarin.AndroidTools\Sessions\AndroidDeploySession.cs:line 113
1>An item with the same key has already been added.
1>Done executing task "InstallPackageAssemblies".
1>Task "Touch"
1>Task Parameter:Files=obj\IDebug\upload.flag
1>Task Parameter:AlwaysCreate=True
1>Touching "obj\IDebug\upload.flag".
1>Done executing task "Touch".
1>Task "MakeDir" skipped, due to false condition; (!Exists('$(_ConfigurationCacheDirectory)')) was evaluated as (!Exists('obj\.cache\')).
1>Task "WriteLinesToFile"
1>Task Parameter:File=obj\.cache\com.outcoder.ibrowser.flag
1>Task Parameter:Lines=IDebugAnyCPU
1>Task Parameter:Overwrite=True
1>Done executing task "WriteLinesToFile".
1>Done building target "_Upload" in project "Outcoder.Browser.Launcher.Android.csproj".
1>Target "Install" in file "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\Android\Xamarin.Android.Common.Debugging.targets" from project "C:\TS\Browser\Mono\Source\Outcoder.Browser\Browser.Launcher.Android\Outcoder.Browser.Launcher.Android.csproj" (entry point):
1>Done building target "Install" in project "Outcoder.Browser.Launcher.Android.csproj".
1>Done building project "Outcoder.Browser.Launcher.Android.csproj".
1>Build succeeded.
1>An error occured. See full exception on logs for more details.
1>An item with the same key has already been added.
1>
========== Deploy: 0 succeeded, 1 failed, 0 skipped ==========
Comment 1 Jon Douglas [MSFT] 2017-09-18 14:46:35 UTC
Hi Daniel,

Thanks for the report! Based on the logs you've provided it seems like there might be an issue with Fast Deployment. Have you tried to disable Fast Deployment in your Android Options inside your project?

Can you please also add your version information to this bug? This way we have a better idea of what versions of tools you are using when running into this issue.

Finally a few things to try:

1. Uninstall your application, Mono runtime, Mono API levels from your development device via the "Apps" application and uninstalling each of them.
2. Try to deploy your application with Fast Deployment enabled (This might take some time to reinstall the API levels, runtime, etc to device.
3. If that doesn't work, please try turning off fast deployment to see if that works, if it does we can start to investigate further into why fast deployment is failing.

Thank you!
Comment 2 Daniel Vaughan 2017-09-20 09:59:53 UTC
Thanks for investigating, Jon.

I'm using Visual Studio version 15.3.4
Xamarin Android 7.4

I uninstalled the Shared Runtime and API app.
Enabled fast deployment.
The app failed to debug (same error).

Disabled fast deployment, I am able to debug.
Comment 3 Jon Douglas [MSFT] 2017-09-20 15:55:41 UTC
(In reply to Daniel Vaughan from comment #2)
> Thanks for investigating, Jon.
> 
> I'm using Visual Studio version 15.3.4
> Xamarin Android 7.4
> 
> I uninstalled the Shared Runtime and API app.
> Enabled fast deployment.
> The app failed to debug (same error).
> 
> Disabled fast deployment, I am able to debug.

I am marking this issue as CONFIRMED based on this comment. If it's possible at all, please upload a project that you are seeing this happen on and reproduction steps if any are needed. You can start with a File -> New Xamarin.Android project as a baseline if this is occurring in every project you attempt to debug.