Missing lock in ProjectAssemblyReferenceCollection

SyntaxEditor .NET Languages Add-on for WPF Forum

Posted 2 years ago by Tobias Lingemann - Software Devolpment Engineer, Vector Informatik GmbH
Version: 22.1.1
Platform: .NET 4.8
Environment: Windows 10 (64-bit)
Avatar

Hi there,

we have encuntered an exception in the class ProjectAssemblyReferenceCollection:

System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at System.Collections.Generic.List`1.Enumerator.MoveNextRare()
   at ActiproSoftware.Internal.Ov.get_Item(String  )
   at ActiproSoftware.Internal.Ov.Add(IAssembly assembly)

I have looked at the source code and found that there is missing a lock in the index overloads. While the actual insertion is secured by a lock in the base class SimpleSynchronizedCollection, the index operator uses foreach over the collection.

As a workaround I can add the locks myself, but I just wish the collections were really thread-safe and not just parts of it. With the old WinForms version we at least knew the classes were not thread-safe. But now some operations are thread-safe while others are not. And usually the problems are found by the customers or very late during development.

[Modified 2 years ago]


Best regards, Tobias Lingemann.

Comments (1)

Posted 2 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

For the next release we updated the SimpleSynchronizedCollection base class to include a protected TryFindItem method that includes the necessary lock and updated each of the indexed properties in ProjectAssemblyReferenceCollection to use the new thread-safe method when searching for the desired assemblies.  Thank you for bringing this to our attention.


Actipro Software Support

The latest build of this product (v24.1.2) was released 13 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.