web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

CRM Plugins Error - An item with the same key has already been added

(0) ShareShare
ReportReport
Posted on by

Hi,

In our Opportunity Update Post-Operation Synchronous plugin, we got the following error:

An item with the same key has already been added


Here's the stack trace:

at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Update(Entity entity, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode) at Microsoft.Crm.Extensibility.InprocessServiceProxy.UpdateCore(Entity entity) at CRMPlugIns.Opportunity.Opportunity_Update_Post.ExecuteLogic()


I don't understand how this is possible since I don't use the entity.Attributes.Add(key, value) method. I simply set the value of an attribute like this: entity["attributeName"] = attribute value.

Any ideas?

Thank you!

*This post is locked for comments

I have the same question (0)
  • ashlega Profile Picture
    34,477 on at

    It should not be doing it with entity["attributeName"] syntax, but, maybe, there is another plugin involved?

  • Suggested answer
    jestuder Profile Picture
    158 on at

    Can you debug the plugin and the specific method?  If so you best beat is to input a break point right before the error happens in your code.  You might also want to add a try catch around your block of code to get even more details.

  • Jeet Gandhi Profile Picture
    320 on at

    Hi,

    Anatoliy

    Please provide the complete code you have used as it seems like the error is coming from any other part of the plugin.

    Also, I suggest you to enable the traces in the plugin in order to get the exact location of the cause of the error.

    Thank you,

  • Community Member Profile Picture
    on at

    Alex: it's possible. Altough, I haven't seen this error occur for the past 2 weeks. I'm starting to think the code changes we made recently to refactor the plugin fixed the issue.

    James: I can't debug the plugin unless I create a console project to emulate an entity being updated. Glad you asked this question. We really should start thinking about setting up mock tests for all our Plugin methods.

    Jeet: Good idea. I think we will enable traces when we see this error happening consistently. It's been 2 weeks since I last saw this error.

    Thank you all for your response. Some very good ideas came out of this!

  • Suggested answer
    Preeti Sharma Profile Picture
    2,678 on at

    Hi,

    Please check duplicate detection rules enabled for the entity as well.tlThere can be a rule being applied for the field.

    Hope this helps:)

  • Jeet Gandhi Profile Picture
    320 on at

    Hi Anatoliy,

    Thanks for your reply, I suggest you like the answers if you found them helpful. Also please let me know if you require further help for any queries.

    Thanking you,

  • Verified answer
    Community Member Profile Picture
    on at

    Hi Jeet - Thanks for the reminder!

    I asked this same question on the CRMUG forums and got a response worth sharing. Please see below:

    entity.Attributes.Add(key, value) is equivalent to entity[key] = value;
    
    Use the SetAttributeValue
    
    msdn.microsoft.com/.../microsoft.xrm.sdk.entity.setattributevalue.aspx

    Here's a combined list of possible solutions:

    I will mark this answer as the suggested answer so that it's easily visible to individuals with a similar error. Let me know if any of you have a problem with this decision.

    Thank you.

  • Suggested answer
    Varun Singh Profile Picture
    943 on at

    You can also do before assigning the key you can check below

    if ( !PluginExecutionContext.SharedVariables.Contains("keyname")){

    // then assign key

    PluginExecutionContext.SharedVariables.Add("keyname", "XXXXXX");

    }

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans