Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

In C# calling "CreateAnnotation", and getting "Failed to attach the file with exception: An item with the same key has already been added."

Posted on by 105

Hello all, 

I'm writing a tool to parse a large number of backup files from a different CRM (Salesforce) to upload them to the correct records in our Dynamics CRM Online instance.  I have already imported Accounts, Opportunities, Contacts, and Contracts, and I included a new field in each entity that has the old Salesforce ID in it.  I've written a method now that takes a Salesforce ID, and an entity type, and looks up the correct ID from Dynamics CRM.  That's all working.  My next step is trying a test upload of a Note/Annotation.

I'm using the "CreateAnnotation" method from a working CrmServiceClient (I know it's working because that's how I look up the entity ID).  The line of code is...

DynamicsServiceClient.CreateAnnotation(GetEntityString(WhichEntityType), EntityID, theNoteBuilder.GetPropertyDictionary());

  • DynamicsServiceClient is just the instance of CrmServiceClient.
  • GetEntityString just gets me a string like "account" depending on which entity type I'm trying to attach to.
  • EntityID is the ID I found earlier...

And I just figured out what the problem was.  I'll post this anyway in case anyone else has the same problem.  The dictionary I built included the EntityID too because I was trying to do this with the "Create" method first, and I needed the EntityID of the parent entity among the attributes.  When I switched to using "CreateAnnotation", I didn't think of the fact that it requires you to provide the EntityID as one of the parameters, and I was still including it in the dictionary I was building.

So: just make sure you aren't adding the Entity ID twice (the "targetEntityID" parameter in the method)

*This post is locked for comments

  • Verified answer
    Kevin T 9 Profile Picture
    Kevin T 9 105 on at
    RE: In C# calling "CreateAnnotation", and getting "Failed to attach the file with exception: An item with the same key has already been added."

    Not sure how to make the original post into the answer, so I'll just do this...

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,269 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,198 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans