EnumDataListSource - Race condition: An item with the same key has already been added
See original GitHub issueWhich Contentment version are you using?
3.2.0
Which Umbraco version are you using? For example: 8.14.1 - don’t just write v8
9.5.0
Bug summary
Sometimes when /umbraco/backoffice/umbracoapi/content/GetEmptyByKeys
is called multiple times on the same page, it ends up in a race condition where multiple threads tries to populate the _lookout dictionary with the same key.
Steps to reproduce
Setup a blocklist within a blocklist and add blocks of the same type.
ExceptionMessage:
An item with the same key has already been added. Key: MyProject.Models.Enums.ImageLayoutOptions
ExceptionType:
System.ArgumentException, System.Private.CoreLib, Version=5.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e
StackTrace:
at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
at Umbraco.Community.Contentment.DataEditors.EnumDataListSource.PopulateLookup(Type type)
at Umbraco.Community.Contentment.DataEditors.EnumDataListSource.GetValueType(Dictionary`2 config)
at Umbraco.Community.Contentment.DataEditors.EnumDataListSource.GetItems(Dictionary`2 config)
at Umbraco.Community.Contentment.DataEditors.DataListConfigurationEditor.ToValueEditor(Object configuration)
at Umbraco.Cms.Core.Models.Mapping.ContentPropertyDisplayMapper.Map(IProperty originalProp, ContentPropertyDisplay dest, MapperContext context)
at Umbraco.Cms.Core.Models.Mapping.ContentPropertyMapDefinition.Map(IProperty source, ContentPropertyDisplay target, MapperContext context)
at Umbraco.Cms.Core.Mapping.UmbracoMapper.<>c__DisplayClass9_0`2.<Define>b__1(Object source, Object target, MapperContext context)
at Umbraco.Cms.Core.Mapping.UmbracoMapper.Map[TTarget](Object source, Type sourceType, MapperContext context)
at Umbraco.Cms.Core.Mapping.UmbracoMapper.Map[TSource,TTarget](TSource source, MapperContext context)
at Umbraco.Cms.Core.Mapping.MapperContext.Map[TSource,TTarget](TSource source)
at System.Linq.Enumerable.SelectIPartitionIterator`2.ToList()
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Umbraco.Cms.Core.Mapping.MapperContext.MapEnumerable[TSourceElement,TTargetElement](IEnumerable`1 source)
at Umbraco.Cms.Core.Models.Mapping.TabsAndPropertiesMapper.MapProperties(IContentBase content, List`1 properties, MapperContext context)
at Umbraco.Cms.Core.Models.Mapping.TabsAndPropertiesMapper`1.Map(TSource source, MapperContext context)
at Umbraco.Cms.Web.BackOffice.Mapping.ContentMapDefinition.Map(IContent source, ContentVariantDisplay target, MapperContext context)
at Umbraco.Cms.Core.Mapping.UmbracoMapper.<>c__DisplayClass9_0`2.<Define>b__1(Object source, Object target, MapperContext context)
at Umbraco.Cms.Core.Mapping.UmbracoMapper.Map[TTarget](Object source, Type sourceType, MapperContext context)
at Umbraco.Cms.Core.Mapping.UmbracoMapper.Map[TTarget](Object source, MapperContext context)
at Umbraco.Cms.Core.Mapping.MapperContext.Map[TTarget](Object source)
at Umbraco.Cms.Core.Models.Mapping.ContentVariantMapper.CreateVariantDisplay(MapperContext context, IContent content, Language language, String segment)
at Umbraco.Cms.Core.Models.Mapping.ContentVariantMapper.<>c__DisplayClass3_0.<Map>b__0(Language language)
at System.Linq.Enumerable.SelectListIterator`2.ToList()
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Umbraco.Cms.Core.Models.Mapping.ContentVariantMapper.Map(IContent source, MapperContext context)
at Umbraco.Cms.Web.BackOffice.Mapping.ContentMapDefinition.Map(IContent source, ContentItemDisplay target, MapperContext context)
at Umbraco.Cms.Core.Mapping.UmbracoMapper.<>c__DisplayClass9_0`2.<Define>b__1(Object source, Object target, MapperContext context)
at Umbraco.Cms.Core.Mapping.UmbracoMapper.Map[TTarget](Object source, Type sourceType, MapperContext context)
at Umbraco.Cms.Core.Mapping.UmbracoMapper.Map[TTarget](Object source, MapperContext context)
at Umbraco.Cms.Core.Mapping.UmbracoMapper.Map[TTarget](Object source, Action`1 f)
at Umbraco.Cms.Web.BackOffice.Controllers.ContentController.MapToDisplay(IContent content, Action`1 contextOptions)
at Umbraco.Cms.Web.BackOffice.Controllers.ContentController.GetEmpties(IEnumerable`1 contentTypes, Int32 parentId)
at Umbraco.Cms.Web.BackOffice.Controllers.ContentController.GetEmptyByKeysInternal(Guid[] contentTypeKeys, Int32 parentId)
at Umbraco.Cms.Web.BackOffice.Controllers.ContentController.GetEmptyByKeys(ContentTypesByKeys contentTypeByKeys)
at lambda_method943(Closure , Object , Object[] )
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|25_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
Expected result / actual result
No response
Do you have Umbraco ModelsBuilder enabled?
- Yes, it is enabled.
What browsers are you seeing the problem on?
No response
Issue Analytics
- State:
- Created a year ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
An item with the same key has already been added. Key
I am testing write/query time series data to/from InfluxDB v2 using c#. Basically I used pretty much the example provided in the WebInterface ......
Read more >SCSM Orchestrator Error: An item with the same key has ...
It turns out this problem is caused when two entries on an enumeration list have the same internal name value. This can happen...
Read more >An item with the same key has already been added
I've been using the IBM iSeries Client Access ODBC driver to pull data from our enterprise system without any problems for weeks. Suddenly...
Read more >Error "An item with the same key has already been added"
This article helps to fix the error "An item with the same key has already been added". Applies to: Windows Server 2012 R2...
Read more >Error "An item with the same key has already been added Key ...
Issue. When you try to migrate one workbook and one published data source by CMT 2022.2.1, the following error might occur: An item...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So far it seems to work 🎉
@leekelleher It happens at two blocks in my current solution, but I think it was after umbraco 9.3 it began (uncomfirmed). I’ll see if I can setup a clean solution and make it fail there.