Bug 32361 - VS2013 - Thread Debugger Appears to expect unique thread numbering
Summary: VS2013 - Thread Debugger Appears to expect unique thread numbering
Status: RESOLVED DUPLICATE of bug 31965
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: Debugger ()
Version: 3.11 (C5)
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-07-23 10:40 UTC by Rand Lennox
Modified: 2016-05-10 17:04 UTC (History)
6 users (show)

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


Attachments
VS2013 Error (23.11 KB, image/png)
2015-07-23 12:49 UTC, Rand Lennox
Details
Xamarin Log Snippet (30.68 KB, text/plain)
2015-08-18 11:56 UTC, Rand Lennox
Details
VS2013 Output Log (10.39 KB, text/plain)
2015-08-18 11:57 UTC, Rand Lennox
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:
RESOLVED DUPLICATE of bug 31965

Description Rand Lennox 2015-07-23 10:40:45 UTC
I have an application that starts threads in different ways depending on the component (some via Task.Run, some using the IOS Dispatcher, etc.)

After a while, the thread numbers get reused and the VS debugger crashes.  Since the app does quite a bit of background processing, in every debug session I eventually get an error.  The crash is definitely in the debugger, since the app never crashes from this error when running without debugging.


Here's a sample of the output.  Notice that in this example, thread #20 is reused right before the VS debugger crashes:

===============================================================================================================


Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/Xamarin.iOS.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/System.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/SpearFyshiOS.exe
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/Xamarin.Forms.Platform.iOS.dll
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/Xamarin.Forms.Core.dll
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/System.Runtime.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/System.ObjectModel.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/System.Core.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/SQLite.Net.dll
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/System.Xml.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/Mono.Dynamic.Interpreter.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/System.ComponentModel.Composition.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/System.IO.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/System.Collections.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/System.Threading.Tasks.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/System.Globalization.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/System.ComponentModel.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/System.Linq.Expressions.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/System.Xml.ReaderWriter.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/System.Reflection.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/System.Dynamic.Runtime.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/System.Threading.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/System.Runtime.Extensions.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/System.Linq.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/System.Reflection.Extensions.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/System.Diagnostics.Debug.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/System.Net.Http.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/System.Runtime.Serialization.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/System.Text.Encoding.dll [External]
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/Newtonsoft.Json.dll
Loaded assembly: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Bundle/Application/54B26F51-1EA9-443C-A062-AA92FECC9919/SpearFyshiOS.app/SQLite.Net.Platform.XamarinIOS.Unified.dll
Resolved pending breakpoint at 'Main.cs:28,1' to void SpearFysh.iOS.Application.Main (string[] args) [0x0003c].
Resolved pending breakpoint at 'Main.cs:34,1' to void SpearFysh.iOS.Application.TaskScheduler_UnobservedTaskException (object sender, System.Threading.Tasks.UnobservedTaskExceptionEventArgs e) [0x00000].
Resolved pending breakpoint at 'Main.cs:69,1' to void SpearFysh.iOS.Application.CurrentDomain_UnhandledException (object sender, System.UnhandledExceptionEventArgs e) [0x00000].
Resolved pending breakpoint at 'UserDB.cs:432,1' to bool SpearFysh.Mobile.Data.UserDB.ExecuteBlockInTransaction (string userDatabasePath, System.Action<SQLite.Net.SQLiteConnection> block, bool throwExceptionOnError) [0x00043].
Resolved pending breakpoint at 'UserDB.cs:441,1' to bool SpearFysh.Mobile.Data.UserDB.ExecuteBlockInTransaction (string userDatabasePath, System.Action<SQLite.Net.SQLiteConnection> block, bool throwExceptionOnError) [0x00081].
2015-07-23 10:21:34.706 SpearFyshiOS[1329:17474] Warning: Unable to create restoration in progress marker file
Resolved pending breakpoint at 'CloudTransactionUploader.cs:197,1' to void SpearFysh.iOS.CloudTransactionUploader.QueueUploadsAsync (SpearFysh.iOS.CloudTransactionUploader uploader) [0x0009e].
Resolved pending breakpoint at 'CloudTransactionUploader.cs:395,1' to void SpearFysh.iOS.CloudTransactionUploader.QueueOneSegmentForUpload (SpearFysh.iOS.CloudTransactionUploader uploader, SpearFysh.Mobile.Data.CloudTransactionUploadSegment segment) [0x007d8].
Resolved pending breakpoint at 'CloudTransactionDownloader.cs:102,1' to void SpearFysh.iOS.CloudTransactionDownloader.QueueDownloadsAsync (SpearFysh.iOS.CloudTransactionDownloader downloader) [0x0008e].
Resolved pending breakpoint at 'CloudTransactionDownloader.cs:318,1' to void SpearFysh.iOS.CloudTransactionDownloader.QueueOneTransactionForDownload (SpearFysh.iOS.CloudTransactionDownloader downloader, SpearFysh.Mobile.Data.CloudTransaction dbTransaction) [0x0045b].
2015-07-23 10:21:36.354 SpearFyshiOS[1329:17474] File location: /Users/randlennox/Library/Developer/CoreSimulator/Devices/D1F50DDA-32D9-4378-B80F-307629923724/data/Containers/Data/Application/F1EA2B7C-82BA-47CD-B353-E725F10C531F/Library
Thread started:  #2
Thread started:  #3
Thread started: <Thread Pool> #4
Thread started: <Thread Pool> #5
Resolved pending breakpoint at 'CloudTransactionController.cs:228,1' to void SpearFysh.Mobile.Core.CloudTransactionController.FailTransaction (SpearFysh.Mobile.Core.CloudTransactionInfo transactionInfo, string errorMessage) [0x00000].
Resolved pending breakpoint at 'CloudTransactionController.cs:841,1' to void SpearFysh.Mobile.Core.CloudTransactionController.OnUploadCompleted (SpearFysh.Mobile.Core.CloudTransactionSegmentInfo segment, string replyFileName, System.Collections.Generic.Dictionary<string,string> headers) [0x0026a].
Resolved pending breakpoint at 'CloudTransactionController.cs:786,1' to void SpearFysh.Mobile.Core.CloudTransactionController.OnUploadCompleted (SpearFysh.Mobile.Core.CloudTransactionSegmentInfo segment, string replyFileName, System.Collections.Generic.Dictionary<string,string> headers) [0x00146].
Resolved pending breakpoint at 'CloudTransactionController.cs:815,1' to void SpearFysh.Mobile.Core.CloudTransactionController.OnUploadCompleted (SpearFysh.Mobile.Core.CloudTransactionSegmentInfo segment, string replyFileName, System.Collections.Generic.Dictionary<string,string> headers) [0x001b9].
Resolved pending breakpoint at 'CloudTransactionController.cs:430,1' to void SpearFysh.Mobile.Core.CloudTransactionController.OnDownloadReceivedNoData (SpearFysh.Mobile.Core.CloudTransactionInfo transactionInfo, System.Collections.Generic.Dictionary<string,string> headers, int httpStatusCode) [0x00000].
Resolved pending breakpoint at 'CloudTransactionController.cs:541,1' to void SpearFysh.Mobile.Core.CloudTransactionController.OnDownloadCompleted (SpearFysh.Mobile.Core.CloudTransactionInfo transactionInfo, System.Collections.Generic.Dictionary<string,string> headers, string temporaryFilePhysicalPath) [0x00020].
Resolved pending breakpoint at 'CloudTransactionController.DataSync.cs:46,1' to void SpearFysh.Mobile.Core.CloudTransactionController.SetHasCompletedInitialDataSync (SpearFysh.Mobile.Core.CloudIdentityInfo identity, bool value) [0x00000].
Resolved pending breakpoint at 'CloudTransactionController.DataSync.cs:51,1' to void SpearFysh.Mobile.Core.CloudTransactionController.SaveSyncMessage (SpearFysh.Mobile.Core.CloudIdentityInfo identity, bool isForInitialSync, SpearFysh.Mobile.Core.CloudTransaction.IMessageProvider message) [0x00000].
Resolved pending breakpoint at 'CloudTransactionController.DataSync.cs:58,1' to void SpearFysh.Mobile.Core.CloudTransactionController.RepostLastSyncMessage (SpearFysh.Mobile.Core.CloudIdentityInfo identity, SpearFysh.Mobile.WebApi.FileTransfer.FileKinds fileKind, bool isForInitalSync) [0x00000].
Thread started: <Thread Pool> #6
2015-07-23 10:21:38.853 SpearFyshiOS[1329:17474] Reachability changed: Monitor Type: RemoteHost, Host: www.apple.com, Id: Apple, IsReachable: True
2015-07-23 10:21:38.853 SpearFyshiOS[1329:17474] Reachability changed: Monitor Type: RemoteHost, Host: www.google.com, Id: Google, IsReachable: True
Thread started: <Thread Pool> #7
Thread started: <Thread Pool> #8
Thread started:  #9
Thread started:  #10
Resolved pending breakpoint at 'PieProgress.cs:251,1' to Foundation.NSAttributedString SpearFysh.iOS.Controls.PieProgress.GetRenderedText (CoreGraphics.CGRect rect, System.nfloat lineHeight) [0x00000].
Thread started:  #11
Thread started:  #13
Thread started:  #14
Thread started:  #15
Thread started:  #16
Thread started:  #17
Thread started:  #18
Thread started:  #19
Resolved pending breakpoint at 'DataSyncDownloadHandler.cs:233,1' to void SpearFysh.Mobile.Core.CloudTransaction.DataSyncDownloadHandler.PackageProcessor.ProcessObjectConfigurations (SpearFysh.Mobile.Core.CloudIdentityInfo identity, System.Collections.Generic.List<SpearFysh.Mobile.WebApi.ObjectConfiguration> serverItems, string configurationHash, System.Collections.Generic.Dictionary<string,SpearFysh.Mobile.WebApi.DataSynchronization.ItemCountInfo> counts, SQLite.Net.SQLiteConnection dc) [0x00001].
Thread started:  #20
Thread started:  #21
Thread started:  #22
Resolved pending breakpoint at 'C:\Projects\SpearFysh\RootApps\trunk\SpearFysh.Mobile\SpearFysh\SpearFysh\Core\ServerObjectProcessor.cs:1430,1' to bool SpearFysh.Mobile.Core.ServerObjectProcessor.MergeNormalMobileObject (SpearFysh.Mobile.WebApi.MobileObject webItem, SQLite.Net.SQLiteConnection dc) [0x001d5].
Thread started:  #23
Thread started:  #24
Thread started:  #20
System.ArgumentException: An item with the same key has already been added.
   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at Xamarin.VisualStudio.Debugger.Process.OnThreadStart(Object sender, TargetEventArgs args)
   at Mono.Debugging.Client.DebuggerSession.OnTargetEvent(TargetEventArgs args)
   at Mono.Debugging.Soft.SoftDebuggerSession.HandleThreadStartEvents(ThreadStartEvent[] events)
   at Mono.Debugging.Soft.SoftDebuggerSession.HandleEventSet(EventSet es)
   at Mono.Debugging.Soft.SoftDebuggerSession.EventHandler()
Running SpearFyshiOS
Comment 1 Rand Lennox 2015-07-23 12:49:03 UTC
Created attachment 12187 [details]
VS2013 Error

In addition to the error in the VS2013 output window, this message pops up in VS2013 when the error occurs.
Comment 2 Mohit Kheterpal 2015-08-18 08:17:01 UTC
Today I am looking into this issue but I am not sure about the steps to reproduce this issue. So, could you please provide test sample so that we can reproduce this issue at our end ?

It would be helpful if you provide zip xamarin logs via help-> Xamarin->Zip
Xamarin logs.

Thanks
Comment 3 Rand Lennox 2015-08-18 11:56:35 UTC
Created attachment 12550 [details]
Xamarin Log Snippet
Comment 4 Rand Lennox 2015-08-18 11:57:09 UTC
Created attachment 12551 [details]
VS2013 Output Log
Comment 5 Rand Lennox 2015-08-18 12:06:22 UTC
I attached the Xamarin Log and VS2013 output window from a debug run where this occurred.

I really can't create a sample, nor can I provide access to the code.  

The code is a proprietary application and I can't release it without breaking IP control rules in my company.   Also, it's somewhere in the neighborhood of 900K+ lines of code, so getting a "snippet" would be a problem, and I'm at a startup working 80-100 hours a week so I don't have the time to play around with creating a separate application that may or may not reproduce the problem.

I would be willing to contact someone when it occurs and share the session via join.me, but to do this I'd need a contact I could reach at any time when the issue happens.

It does appear to be a simple duplicate key issue in a Dictionary<Tkey, TValue> object...isn't it possible to just find the code in the VS extension and replace the dictionary with something more appropriate (something that does not depend on thread id's being unique integers???)

How do you suggest we proceed?
Comment 6 Rand Lennox 2015-08-18 12:25:41 UTC
One additional point that may be helpful - the application does start a thread when a background download from IOS is completed.  It appears that when I "turn off" the background sync code (comment it out), then I do not get duplicate thread ids.  It's important to note that the code being commented out runs successfully many times before the error condition happens (sometimes it runs for several hours, sometimes for just a few minutes - classic race condition).

The background code is fired from a subclass of NSUrlSessionDownloadDelegate, in the following override:

public override void DidFinishDownloading(NSUrlSession session, NSUrlSessionDownloadTask downloadTask, NSUrl location)

Note that this may not be the cause of the error - it's just a possibility.  Commenting out the download ALSO reduces the number of background threads, so it might be a race condition that is alleviated by removing this code rather than actually being caused by the code.  

The real problem seems to be that the VS2013 extension expects that thread id's will be unique, when in fact they may not be.  This will definitely be the case if the extension uses the ManagedThreadId property, because it will definitely be reused.  Per Stack Overflow: 

'ManagedThreadId is not a robust approach to identify threads as the ManagedThreadId property id's get reused by your app. So it is not a reliable identifier for threads in some scenarios and you will experience the exception : "An item with the same key has already been added." at line... Give the thread a unique name when you create it."'

Again, this is just a guess - I'm not sure how the VS extension tracks threads...
Comment 7 arx iT 2015-09-02 07:16:09 UTC
Seems to be a duplicate of : https://bugzilla.xamarin.com/show_bug.cgi?id=31965
Comment 8 Rand Lennox 2015-09-02 11:17:55 UTC
I agree - this is a duplicate.
Comment 9 Rand Lennox 2015-09-02 11:19:34 UTC
Closing this as a duplicate of 31965.

*** This bug has been marked as a duplicate of bug 31965 ***