Search code examples
c#sql-server.net-coremodel-view-controllerumbraco

An item with the same key has already been added. Key: 1056


I am developing new application by using Umbraco version 10.3.1. I am getting below exception.

I have generated script to back up Database from existing Database. I connected to new database and ran the application then I got this exception. And connected back to old Database then it is also not working. same exception.

ArgumentException: An item with the same key has already been added. Key: 1056
System.Collections.Generic.Dictionary<TKey, TValue>.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
System.Linq.Enumerable.ToDictionary<TSource, TKey>(List<TSource> source, Func<TSource, TKey> keySelector, IEqualityComparer<TKey> comparer)
Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.ContentTypeCommonRepository.MapHistoryCleanup(Dictionary<int, IContentTypeComposition> contentTypes)
Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.ContentTypeCommonRepository.GetAllTypesInternal()
Umbraco.Extensions.AppCacheExtensions+<>c__DisplayClass0_0<T>.<GetCacheItem>b__0()
Umbraco.Cms.Core.Cache.SafeLazy+<>c__DisplayClass1_0.<GetSafeLazy>b__0()
Umbraco.Cms.Core.Cache.ObjectCacheAppCache.Get(string key, Func<object> factory, Nullable<TimeSpan> timeout, bool isSliding, string[] dependentFiles)...
SixLabors.ImageSharp.Web.Middleware.ImageSharpMiddleware.Invoke(HttpContext httpContext, bool retry)
StackExchange.Profiling.MiniProfilerMiddleware.Invoke(HttpContext context) in MiniProfilerMiddleware.cs
Umbraco.Cms.Web.Common.Middleware.UmbracoRequestMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
Umbraco.Cms.Web.Common.Middleware.UmbracoRequestMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)

Previously Site was working fine but after this script generation getting this exception.


Solution

  • You most likely have duplicate property aliases. Removing the duplication should fix your problem.

    Depending on your Umbraco version, one of the following answers could help. Use this Umbraco forum for more specific answers for your Umbraco version and remember to add details like version numbers next time you create a question - this will help you get better answers.

    Answer one: https://our.umbraco.com/forum/using-umbraco-and-getting-started/82354-an-item-with-the-same-key-has-already-been-added#comment-267015 enter image description here

    Answer two: https://our.umbraco.com/forum/using-umbraco-and-getting-started/109281-an-item-with-the-same-key-has-already-been-added-upgrade-error-umbraco-8-to-umbraco-9 enter image description here

    Answer three: https://our.umbraco.com/forum/templates-partial-views-and-macros/91919-an-item-with-the-same-key-has-already-been-added enter image description here