microsoft/ClearScript

Add ConcurrentPropertyBag

irineu opened this issue · 2 comments

Hi, i'm trying the ClearScript solution in a specific scenario with concurrency. I've got an exception and i didn't found a solution on ClearScript docs for solve it:

System.InvalidOperationException: Operations that change non-concurrent collections must have exclusive access. A concurrent update was performed on this collection and corrupted its state. The collection's state is no longer correct. at System.Collections.Generic.Dictionary2.TryInsert(TKey key, TValue value, InsertionBehavior behavior) at Microsoft.ClearScript.PropertyBag.Add(String key, Object value)

The error is in: Microsoft.ClearScript.PropertyBag.Add, and after look the source code of the PropertyBag class (https://github.com/microsoft/ClearScript/blob/ebd71aaf9e198b549a2e4dcdd8b61b21fefd7841/ClearScript/PropertyBag.cs#L36C9-L36C64), replacing the Dictionary to ConcurrentDictionary may solve this problem... But it will be nice if the ClearScript have an built in solution for deal with concurrency...

Hello, @irineu,

We'll add a ConcurrentPropertyBag class in the next release. In the meantime, you can use a custom IPropertyBag implementation. Subclassing PropertyBag could be another option, depending on your exact requirements.

Thanks for the suggestion!