November Happy Hour will be moved to Thursday December 5th.

"An item with the same key has already been added"

Vote:
 

This is my scenario:

I am using UnifiedSearchFor to search in content types together with a few custom types. For one of the custom types (Employee) I want to show some additional info in the search hit compared to a hit for e.g a standard content page.

To do this I have added the following conventions:

SearchClient.Instance.Conventions.UnifiedSearchRegistry
.Add();
SearchClient.Instance.Conventions
.ForInstancesOf()
.IncludeField(e => e.EmployeeMetaData());
SearchClient.Instance.Conventions.UnifiedSearchRegistry
.ForInstanceOf()
.ProjectMetaDataFrom(e => e.EmployeeMetaData());

where the extensionmethod EmployeeMetaData looks something like this:

private static IDictionary EmployeeMetaData(this Employee e)
        {                           
            var metaData = new Dictionary
            {
                {"Titel", e.Title},
                {"Telefon", e.Phone},
                {"Mobil", e.CellPhone},
                {"E-post", e.Email},
            };

            return metaData;
        }

So far so good, the UnifiedSearchHit.MetaData contains the info I want to show. However, when I call Client.Get(id) I get: "System.ArgumentException: An item with the same key has already been added". 

Stack trace:

[ArgumentException: An item with the same key has already been added.]
   System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) +52
   System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) +10925834
   System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value) +10

[TargetInvocationException: Exception has been thrown by the target of an invocation.]
   System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
   System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +92
   System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +108
   EPiServer.Find.Json.DictionaryConverter.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer) +637
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target) +327
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id) +1671
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) +517
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue) +184
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) +791
   Newtonsoft.Json.Serialization.JsonSerializerProxy.DeserializeInternal(JsonReader reader, Type objectType) +75
   Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) +46
   EPiServer.Find.Api.SearchHitConverter.PopulateItemProperty(JsonReader reader, JsonSerializer serializer, Type objectType, Object item) +99
   EPiServer.Find.Api.SearchHitConverter.PopulateProperty(JsonReader reader, JsonSerializer serializer, Type objectType, String propertyName, Object item) +65
   EPiServer.Find.Json.IgnoredPropertiesHandlingConverterBase.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer) +425
   Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent) +791
   Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType) +1144
   Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader, Type objectType) +46
   Newtonsoft.Json.JsonSerializer.Deserialize(JsonReader reader) +128
   EPiServer.Find.Api.GetCommand`1.Execute() +370
   EPiServer.Find.Client.GetWithMeta(DocumentId id, Action`1 commandAction) +329
   EPiServer.Find.Client.Get(DocumentId id, Action`1 commandAction) +56
   EPiServer.Find.Client.Get(DocumentId id) +55

Is this some bug or am I simply doing this the wrong way?

#90237
Sep 04, 2014 10:57
Vote:
 

Any particular reason you are putting the values in a dictionary? The way I see it, would it not be better to create a MetaData class and populate that instead? That would not mess up the deserialization and it would also make it a lot easier to query.

EDIT: Right, because of ProjectMetaDataFrom. I guess I should have read the entire question ;-)

#90342
Edited, Sep 08, 2014 8:48
Vote:
 

Hi,

So this is a bug then. Problem occurs when we are deserializing the dictionary and it is static like that. Meaning it is already there. We need to fail silently here then I assume.

I have added a bug for this. We will look at it as soon as possible.

/Marcus

#90352
Sep 08, 2014 9:56
Vote:
 

Ok, thanks! I forgot to mention that we are currently using version 8.0.3.411 of Find, if you need it for the bug report.

/Gustav

#90361
Sep 08, 2014 11:49
Vote:
 
An item with the same key has already been added.
I'm getting this error on my production.

the Epi find version: 13.4.3
EPiServer.ContentDeliveryApi.Search 2.18.0
EPiServer.ContentDeliveryApi 2.4.0
any idea how can I fix that on my prod?
I can't replicate that on my local


Step to reproduce:
for the replication
I added a new link to the a linkitem collection area
wait for showing the autosave
nothing happened
refresh the page
page marked as published
even after the reverting the page can't edit and publish again

2021-04-27T00:39:34,Error,wgap01mstr6sdl6prod,426871,637550807746335514,0,10896,304,"EPiServer.Find.Cms.ContentEventIndexer : An exception occurred while indexing (IContent): 20739_94395. An item with the same key has already been added.. System.ArgumentException: An item with the same key has already been added. at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add) at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer) at EPiServer.ContentApi.Core.Serialization.ContentModelMapperBase.Convert(IContent content, ConverterContext converterContext) at EPiServer.ContentApi.Core.Serialization.ContentConvertingService.ConvertToContentApiModel(IContent content, ConverterContext converterContext) at EPiServer.Find.DelegateValueProvider`2.GetValue(Object target) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.CalculatePropertyValues(JsonWriter writer, Object value, JsonContainerContract contract, JsonProperty member, JsonProperty property, JsonContract& memberContract, Object& memberValue) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType) at EPiServer.Find.Json.CustomWriteConverterBase.WriteNonIgnoredProperty(JsonSerializer serializer, JsonProperty property, Object propertyValue, JsonWriter writer) at EPiServer.Find.Json.CustomWriteConverterBase.WriteNonIgnoredProperties(JsonWriter writer, Object value, JsonSerializer serializer) at EPiServer.Find.Cms.Json.MaxDepthContentAreaConverter.WriteJson(JsonWriter writer, Object value, JsonSerializer serializer) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeConvertable(JsonWriter writer, JsonConverter converter, Object value, JsonContract contract, JsonContainerContract collectionContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType) at EPiServer.Find.Api.ActionConverterBase.WriteJson(JsonWriter writer, Object value, JsonSerializer serializer) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeConvertable(JsonWriter writer, JsonConverter converter, Object value, JsonContract contract, JsonContainerContract collectionContract, JsonProperty containerProperty) at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType) at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType) at EPiServer.Find.Json.Serializer.SerializeToTextWriter(JsonSerializer serializer, Object value, TextWriter textWriter) at EPiServer.Find.Json.Serializer.SerializeObjectsToJsonRequest(JsonSerializer serializer, IJsonRequest jsonRequest, IEnumerable values) at EPiServer.Find.Api.CommandBase`3.Execute() at EPiServer.Find.Client.IndexDirectly(IEnumerable objectsToIndex, Boolean deleteLanguageRoutingDuplicatesOnIndex) at EPiServer.Find.Client.Index(IEnumerable objectsToIndex, Boolean deleteLanguageRoutingDuplicatesOnIndex) at EPiServer.Find.Cms.ContentIndexer.IndexWithRetry(IContent[] contents, Int32 maxRetries, Boolean deleteLanguageRoutingDuplicatesOnIndex) at EPiServer.Find.Cms.ContentIndexer.Index(IEnumerable`1 contents, IndexOptions options) at EPiServer.Find.Cms.ContentEventIndexer.Index(IContent content, Boolean cascade, Func`2 cascadeFilter)",
#253950
Edited, Apr 27, 2021 0:50
Vote:
 

Does anyone has any idea ?

I found this link related to that issue here but it doesn't help:

 can't find  a file called LinkItemCollection.cshtml nor the mentioned line

https://support.episerver.com/hc/en-us/articles/115002345291?page=1#comment_360013502551

I'm getting error when trying to add a new link to LinkItemCollection

I searched a lot but can't find any solution, seems it's a bug or internal issue in Epi

 

here is the Epi version I'm using:

<package id="EPiServer.AddOns.Helpers" version="0.4.0.0" targetFramework="net461" />
<package id="EPiServer.Azure" version="9.4.4" targetFramework="net461" />
<package id="EPiServer.CMS" version="11.11.2" targetFramework="net462" />
<package id="EPiServer.CMS.AspNet" version="11.20.6" targetFramework="net462" />
<package id="EPiServer.CMS.CloudSynchronization" version="1.1.1" targetFramework="net462" />
<package id="EPiServer.CMS.Core" version="11.20.6" targetFramework="net462" />
<package id="EPiServer.CMS.TinyMce" version="2.4.0" targetFramework="net462" />
<package id="EPiServer.CMS.UI" version="11.27.0" targetFramework="net462" />
<package id="EPiServer.CMS.UI.Core" version="11.27.0" targetFramework="net462" />
<package id="EPiServer.ConnectForMarketingAutomation" version="5.6.0" targetFramework="net462" />
<package id="EPiServer.ContentDeliveryApi" version="2.4.0" targetFramework="net461" />
<package id="EPiServer.ContentDeliveryApi.Cms" version="2.18.0" targetFramework="net462" />
<package id="EPiServer.ContentDeliveryApi.Core" version="2.18.0" targetFramework="net462" />
<package id="EPiServer.ContentDeliveryApi.OAuth" version="2.2.0" targetFramework="net461" />
<package id="EPiServer.ContentDeliveryApi.Search" version="2.18.0" targetFramework="net462" />
<package id="EPiServer.Find" version="13.4.3" targetFramework="net462" />
<package id="EPiServer.Find.Cms" version="13.4.3" targetFramework="net462" />
<package id="EPiServer.Find.Framework" version="13.4.3" targetFramework="net462" />
<package id="EPiServer.Forms" version="4.24.3" targetFramework="net462" />
<package id="EPiServer.Forms.Core" version="4.24.3" targetFramework="net462" />
<package id="EPiServer.Forms.Samples" version="3.5.0" targetFramework="net462" />
<package id="EPiServer.Forms.UI" version="4.24.3" targetFramework="net462" />
<package id="EPiServer.Framework" version="11.20.6" targetFramework="net462" />
<package id="EPiServer.Framework.AspNet" version="11.20.6" targetFramework="net462" />
<package id="EPiServer.GoogleAnalytics" version="2.3.2" targetFramework="net462" />
<package id="EPiServer.Insight.Cms" version="1.7.2" targetFramework="net461" />
<package id="EPiServer.Insight.UI" version="1.7.2" targetFramework="net461" />
<package id="EPiServer.InstantTemplates" version="1.0.3-beta" targetFramework="net462" />
<package id="EPiServer.Logging.Log4Net" version="2.2.2" targetFramework="net461" />
<package id="EPiServer.Marketing.Automation.Forms" version="2.3.0" targetFramework="net462" />
<package id="EPiServer.Marketing.KPI" version="2.5.4" targetFramework="net462" />
<package id="EPiServer.Marketing.Messaging" version="1.3.0" targetFramework="net461" />
<package id="EPiServer.MarketingAutomationIntegration.Salesforce" version="4.2.1" targetFramework="net462" />
<package id="EPiServer.Packaging" version="3.4.0" targetFramework="net462" />
<package id="EPiServer.Personalization.MaxMindGeolocation" version="1.0.0" targetFramework="net461" />
<package id="EPiServer.Profiles.Client" version="1.7.2" targetFramework="net461" />
<package id="EPiServer.Profiles.Client.Common" version="1.7.2" targetFramework="net461" />
<package id="EPiServer.ServiceLocation.StructureMap" version="2.0.1" targetFramework="net461" />
<package id="EPiServer.TinyMCESpellChecker" version="2.0.0" targetFramework="net462" />
<package id="EPiServer.Tracking.Cms" version="1.7.2" targetFramework="net461" />
<package id="EPiServer.Tracking.Core" version="1.7.2" targetFramework="net461" />
<package id="EPiServer.Tracking.PageView" version="1.1.0" targetFramework="net461" />
<package id="EPiServer.Turnstile.Contracts.Hmac" version="2.0.1" targetFramework="net462" />
<package id="EPiServer.VisitorGroupsCriteriaPack" version="2.0.1" targetFramework="net461" />

#256152
Jun 07, 2021 7:35
Vote:
 

To me the same thing happens to me.

I have searched for @target in my entire project and have not.
since my front is with react.

This is not the solution.


@ Html.PageLink (linkItem.Text, basePage.PageLink, new {language = basePage.LanguageBranch}, new {@target = "_blank"})

any more ideas?
#261137
Aug 26, 2021 11:04
Vote:
 

Hi Gustav,

While the bug is being resolved by optimizely is it possible to maybe refactor your solution to use a typedsearch with projections?

I believe this will not have the same issue or can be handled to fail gracefully.

Paul

#268267
Dec 11, 2021 23:07
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.