Skip to content
This repository was archived by the owner on Jun 19, 2024. It is now read-only.
This repository was archived by the owner on Jun 19, 2024. It is now read-only.

GetServiceAsync is not thread safe #51

Open

Description

@cprice70

GetServiceAsync crashes with the following exception, it appears that the collection is being modified at the same time that it is trying to enumerate the services. The exception happens when this line is called

var s = device.Services.First (x => x.ID == id);

System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
at System.ThrowHelper.ThrowInvalidOperationException (ExceptionResource resource) [0x0000b] in :0
at System.Collections.Generic.List1+Enumerator[Robotics.Mobile.Core.Bluetooth.LE.IService].MoveNextRare () [0x00016] in <filename unknown>:0 at System.Collections.Generic.List1+Enumerator[Robotics.Mobile.Core.Bluetooth.LE.IService].MoveNext () [0x00050] in :0
at System.Linq.Enumerable.First[IService](IEnumerable1 source, System.Func2 predicate, Fallback fallback) [0x00026] in :0
at System.Linq.Enumerable.First[IService](IEnumerable1 source, System.Func2 predicate) [0x00007] in :0
at Robotics.Mobile.Core.Bluetooth.LE.Extensions+c__AnonStorey1.<>m__1 (System.Object sender, System.EventArgs e) [0x0002a] in /Users/cprice1/Projects/Monkey.Robotics/Source/Platform Stacks/Robotics.Mobile.Core/Bluetooth/LE/Extensions.cs:78
at --- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in :0
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x0004e] in :0
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x0002e] in :0
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x0000b] in :0
at System.Runtime.CompilerServices.TaskAwaiter`1[Robotics.Mobile.Core.Bluetooth.LE.IService].GetResult () [0x00000] in :0
at IDS.BluetoothAdapter+c__async0.MoveNext () [0x000a4] in /Users/cprice1/Projects/Control/Control/IDS/IDS.BluetoothAdapter.cs:175
at --- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000b] in :0
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.m__1 (System.Object state) [0x00000] in :0

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions