This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Description
Scenario:
- Set up a memory cache.
- Add an entry with a cancellation token registered with it.
- Start a child thread which keep reading the memory cache with the same key.
- Reset the value of the entry from main thread.
- Exception
InvalidOperationException is thrown.
Issue repo:
https://github.com/troydai/CachingIssues/blob/2a85107b9b572c47d66d2a0303deafecaeaa3166/TestActions/ConcurrencyIssue184.cs#L17
Run the sample follow exception will be thrown from child thread after the value is updated by main thread.
Unhandled Exception: 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 Microsoft.Extensions.Caching.Memory.CacheEntry.PropageOptions(CacheEntry parent)
at Microsoft.Extensions.Caching.Memory.MemoryCache.TryGetValue(Object key, Object& result)
at Microsoft.Extensions.Caching.Memory.CacheExtensions.TryGetValue[TItem](IMemoryCache cache, Object key, TItem& value)
at Microsoft.Extensions.Caching.Memory.CacheExtensions.Get[TItem](IMemoryCache cache, Object key)
at ConsoleApplication.Program.<>c__DisplayClass5_0.<Monitor>b__0(Int32 round, DateTime beginning)
at ConsoleApplication.Program.<>c__DisplayClass4_0.<Polling>b__0()
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)