Second Life of a Hungarian SharePoint Geek

April 22, 2010

TermStoreOperationException provides no help when you need to localize the source of the error

Filed under: SP 2010, Taxonomies — Tags: , — Peter Holpar @ 14:58

Recently I work a lot with taxonomy data from code. As you might already know, there one should call the CommitAll method of the TermStore instance after you made the required modifications in the current session to commit all the changes in a single batch. If you are not familiar with it, you can find more information about this things here.

In my tool (see a former version here) I load a lot of taxonomy terms into multiple term sets. If I try to create a term that already exists I get a TermStoreOperationException that says “There is already a term with the same default label and parent term.”. The issue in this case is that you get the exception on commit, not immediately when you call the method that creates the term, and since the TermStoreOperationException provides no extra information (what parent term or what term label) about the details it is quite hard to localize the source of the problem.

Although in my case the code checked if there is a term having the same name as the new one, I ignored the fact that term labels (similar to group names and term set names) are case insensitive, and compared the labels for equality. After applying the ToLower() method to both sides of the relation the problem was eliminated.

It is OK for now, but I feel that the TermStoreOperationException was not really designed with developers in mind. It works for user interface modifications where you create a single term per transaction but it suffers when you have to work with a lot of modifications in a single transaction.



  1. You are 100% correct. SharePoint has many obscure exceptions that say nothing but “Object reference not set to an instance” (in SPImport) or “Cannot complete the operation”, and it’s very difficult to troubleshoot the problem.

    Comment by Sruli Ganor — April 25, 2010 @ 08:51

  2. What about system.unauthorized access exception? I’m tring to call the termstore.CommitAll() function but it isnt cooperating, I have windows authentication enabled on the application pool of the web service in which the code is being run, I am running the code with elevated privileges (which grants read access) and site.allowunsafeupdates = true at the time of the execution. I am always signed on as the site administrator, it doesnt work

    have you encountered this error in the past?

    Comment by brian — November 16, 2010 @ 21:13

    • Hi Brian,

      Do you have administrative rights for the Managed Metadata service application?


      Comment by Peter Holpar — December 2, 2010 @ 22:38

  3. I am having an issue where I get this ‘already exists’ error creating a term when term labels differ by a space:

    “99 Foobar J&J” is taken as equal to “99 Foobar J& J” … this doesn’t make a lot of sense to me. Is it documented how these are processed? I’d like to detect this equality so I can avoid to create duplicates in the first place if the term store considers them equal…

    Comment by dave — August 24, 2012 @ 17:55

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at

%d bloggers like this: