Jump to content
We have recently updated our Privacy Statement, available here ×

An item with the same key has already been added.


Manoj Chaurasia

Recommended Posts

This is SDK connector to communicate with Sharepoint.

An item with the same key has already been added.

having the issue sometime when loading the fields of the entity.

 

 

I have debugged the code and check the duplicate name of fields and definition but nothing seems to be wrong.

 

RetrieveObjectDefinition method (To get the fields for the selected entity) calls many time for one particular connection, not for others.

 

 

Is there any way to see detail description of this issue in agent folder logs where I can find out that duplicate key name

Link to comment
Share on other sites

Hey Ankit,

Object names cannot be duplicated across the connection and property names cannot be duplicated in an object. This happens commonly when:

 

 

You dynamically generate metadata, you might have duplicate objects or properties.

You are building hierarchal objects, and a nested object has the same name (e.g. VirtualAttachmentFolder and VirtualDocumentFolder each reference their own child object named Attachment).

 

 

I don't think there is logging for this already, but you could write your own. Here is one example:

https://gitlab.com/ScribeSoftware/sample-scribe-platform-api-connector/b...

 

Thanks,

Nate

Link to comment
Share on other sites

Our connector architect has provided the following code snippet that you could run to validate.

 

How to use (Given an IMetadataProvider mp)

 

Snippet:

 

mp.ValidateDuplicates();

 

The code is as follows (not tested, nor cleaned up, but should be close)

 

namespace MetadataDuplicateValidator

{

using Scribe.Core.ConnectorApi;

using System;

using System.Collections.Generic;

using System.Linq;

public static class MetadataValidatorEx

{

public static void ValidateDuplicates(this IMetadataProvider mp)

{

var duplicateActions = GetDuplicateActions(mp);

var objNames = mp.RetrieveObjectDefinitions().Select(x => x.FullName).ToList();

var duplicateObjs = GetDuplicateObjectNames(objNames);

var duplicateProperties = GetDuplicatePropertyNames(mp, objNames);

if (duplicateActions.Count == 0 &&

duplicateObjs.Count == 0 &&

duplicateProperties.Count == 0) { return; }

var actions = FormatActions(duplicateActions);

var objs = FormatObjs(duplicateObjs);

var props = FormatProps(duplicateProperties);

var nl = System.Environment.NewLine;

throw new ApplicationException($"{actions}{nl}{objs}{nl}{props}{nl}");

}

private static string MkList(IEnumerable ss)

{

return string.Join(", ", ss);

}

private static string FormatActions(IList x)

{

return x.Count == 0

"No Duplicate ActionDefinition FullNames."

: $"The following Actions were duplicates: {MkList(x)}.";

}

private static string FormatObjs(IList x)

{

return x.Count == 0

"No Duplicate ObjectDefinition names."

: $"The following ObjectDefinitions were duplicates: {MkList(x)}.";

}

private static string FormatProps(IList x)

{

return x.Count == 0

"No Duplicate PropertyDefinition FullNames."

: $"The following PropertyDefinitions were duplicates: {MkList(x)}.";

}

private static IList GetDuplicateObjectNames(List objs)

{

var duplicateObjNames = new List();

var objNames = new List();

foreach (var objName in objs)

{

if (objNames.Contains(objName)) { duplicateObjNames.Add(objName); }

objNames.Add(objName);

}

return duplicateObjNames;

}

private static IList GetDuplicatePropertyNames(IMetadataProvider mp, IList objs)

{

return objs.SelectMany(x => GetDuplicatePropertyNames(mp, x)).ToList();

}

private static IList GetDuplicatePropertyNames(IMetadataProvider mp, string objName)

{

var objDef = mp.RetrieveObjectDefinition(objName, true);

var listOfNames = new List();

var duplicates = new List();

foreach (var prop in objDef.PropertyDefinitions.Select(x => x.FullName))

{

if (listOfNames.Contains(prop))

{

duplicates.Add($"ObjFullName: {objName}, PropFullName: {prop}");

}

listOfNames.Add(prop);

}

return duplicates;

}

private static IList GetDuplicateActions(IMetadataProvider mp)

{

var actions = mp.RetrieveActionDefinitions().Select(x => x.FullName).ToList();

var duplicateActions = new List();

var actionNames = new List();

foreach (var action in actions)

{

if (actionNames.Contains(action)) { duplicateActions.Add(action); }

actionNames.Add(action);

}

return duplicateActions;

}

}

}

Link to comment
Share on other sites

×
×
  • Create New...