SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to create taxonomies in my central administration. I am trying to do like this. enter image description here When it comes to TermStore class, it is giving this exception. How to resolve this. Is there any mistake in giving the URL of site? Need to activate any services other than Managed MetaData Service

I am adding my complete code here

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.Office;
using Microsoft.SharePoint.Taxonomy;

namespace TaxonomiesEx
    class Program
        static void Main(string[] args)

            using (SPSite site = new SPSite("http://sp2010:8080/personal/Home"))
                    //instantiate a new taxonomy session for the current site.
                    TaxonomySession ts = new TaxonomySession(site);

                    //instantiates the name "Managed Metadata Service Connection" for the current session.
                    TermStore termstore = ts.TermStores["Managed Metadata Service Connection"];

                    //create a group object
                    Group group1 = termstore.CreateGroup("Group1");
                    TermSet termset1 = group1.CreateTermSet("TermSet1");
                    Term term1 = termset1.CreateTerm("Hello", 1033);
                    Term term2 = termset1.CreateTerm("Hi", 1033);
                    Term term3 = termset1.CreateTerm("Glad to meet you", 1033);
                    Term term1a = term1.CreateTerm("How are you", 1033);

                    term1.SetDescription("This is first One", 1033);
                    term1.CreateLabel("First Term", 1033, false);
                    term1.CreateLabel("TermOne", 1033, false);
                catch (Exception e)

                    Console.WriteLine("Error Occured \n {0}",e.Message);

share|improve this question
Can you please add your code that you have written? – Manju Aug 17 '12 at 9:59
@Manju Code added – Mihir Aug 17 '12 at 11:20

Probably you're running this code from Visual Studio, this means the code runs with permissions of the logged in user. Does this user has permissions to access the Managed Metadata Service Application you're using in the code?

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.