Closed
Description
I am trying to save a ParseObject and I run into the following issue:
System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException (ExceptionResource resource) [0x00000] in /Users/builder/data/lanes/1977/2c66d2fe/source/mono/external/referencesource/mscorlib/system/throwhelper.cs:74
at System.Collections.Generic.Dictionary`2[System.String,Parse.ParseObject].Insert (System.String key, Parse.ParseObject value, Boolean add) [0x0008e] in /Users/builder/data/lanes/1977/2c66d2fe/source/mono/external/referencesource/mscorlib/system/collections/generic/dictionary.cs:329
at System.Collections.Generic.Dictionary`2[System.String,Parse.ParseObject].Add (System.String key, Parse.ParseObject value) [0x00000] in /Users/builder/data/lanes/1977/2c66d2fe/source/mono/external/referencesource/mscorlib/system/collections/generic/dictionary.cs:185
at System.Linq.Enumerable.ToDictionary[ParseObject,String,ParseObject] (IEnumerable`1 source, System.Func`2 keySelector, System.Func`2 elementSelector, IEqualityComparer`1 comparer) [0x0002f] in //Library/Frameworks/Xamarin.iOS.framework/Versions/8.10.4.46/src/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:2924
at System.Linq.Enumerable.ToDictionary[ParseObject,String,ParseObject] (IEnumerable`1 source, System.Func`2 keySelector, System.Func`2 elementSelector) [0x00000] in //Library/Frameworks/Xamarin.iOS.framework/Versions/8.10.4.46/src/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:2911
at Parse.ParseObject.CollectFetchedObjects () [0x00034] in <filename unknown>:0
at Parse.ParseObject.MergeFromServer (IObjectState serverState) [0x000d9] in <filename unknown>:0
at Parse.ParseObject.HandleSave (IObjectState serverState) [0x0004a] in <filename unknown>:0
at Parse.ParseObject+<>c__DisplayClass44.<SaveAsync>b__41 (System.Threading.Tasks.Task`1 t) [0x0002a] in <filename unknown>:0
at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2[Parse.Internal.IObjectState,System.Threading.Tasks.Task`1[Parse.Internal.IObjectState]].InnerInvoke () [0x00027] in /Users/builder/data/lanes/1977/2c66d2fe/source/mono/external/referencesource/mscorlib/system/threading/Tasks/TaskContinuation.cs:207
at System.Threading.Tasks.Task.Execute () [0x00016] in /Users/builder/data/lanes/1977/2c66d2fe/source/mono/external/referencesource/mscorlib/system/threading/Tasks/Task.cs:2523
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in /Users/builder/data/lanes/1977/2c66d2fe/source/mono/mcs/class/corlib/System.Runtime.ExceptionServices/ExceptionDispatchInfo.cs:61
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00047] in /Users/builder/data/lanes/1977/2c66d2fe/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:201
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in /Users/builder/data/lanes/1977/2c66d2fe/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:170
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in /Users/builder/data/lanes/1977/2c66d2fe/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:142
at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in /Users/builder/data/lanes/1977/2c66d2fe/source/mono/external/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:124
at MathChat.Exceptions.ServerException+<Wrap>c__async0+<Wrap>c__AnonStorey6+<Wrap>c__async5.MoveNext () [0x00022] in /Users/kostub/Projects/mathchat-xamarin/MathChatShared/Exceptions/ServerException.cs:25
This happens consistently in the debugger and looking through the code it seems to create a mapping of objectId -> Object for all fetched objects.
My structure is as follows:
> problem.problem.estimatedData
Count = 21
[0]: {[ACL, Parse.ParseACL]}
[1]: {[allCollaborators, System.Collections.Generic.List`1[System.Object]]}
[2]: {[chatColors, System.Collections.Generic.List`1[System.Object]]}
[3]: {[collaborators, System.Collections.Generic.List`1[System.Object]]}
> problem.problem.estimatedData["collaborators"][0].ObjectId
"sjtdkpfUj0"
> problem.problem.estimatedData["allCollaborators"][0].ObjectId
"sjtdkpfUj0"
> problem.problem.estimatedData["allCollaborators"][0].IsDataAvailable
true
> problem.problem.estimatedData["collaborators"][0].IsDataAvailable
true
So both the collaborators
and allCollaborators
fields point to the same object and this is causing the exception. Not sure what's the best way to resolve.