I have a piece of code in which I want to check if a specific Term is available within a TermSet. The TermSet is quite large, so getting all Terms is no option here.

My code looks like this:

Getting the correct TermSet:

using (ClientContext cc = _clientContext)
    TaxonomySession session = TaxonomySession.GetTaxonomySession(_clientContext);
    cc.Load(session, s => s.TermStores);
    TermStore termStore = session.TermStores.GetByName(TERM_STORE_NAME);
    cc.Load(termStore, store => store.Groups
        .Where(group => group.Name == TERM_GROUP_NAME)
        .Include(group => group.TermSets
            .Where(termSet => termSet.Name == TERM_SET_NAME)));

    _termSet = termStore.Groups[0].TermSets[0];

Checking if the Term exists within the TermSet:

public bool TermAvailableInTermSet(LabelMatchInformation labelparam)
    LabelMatchInformation label = new LabelMatchInformation(_clientContext)
        TrimUnavailable = false,
        DefaultLabelOnly = false,
        StringMatchOption = StringMatchOption.ExactMatch,
        Lcid = 1033,

    label.TermLabel = "Test";

    TermCollection terms = LocationTermSet.GetTerms(label); 

    return (terms != null && terms.Count > 0);

With this code everything runs like expected until I Execute the query with GetTerms. A really peculiar error is returned: Value cannot be null.\r\nParameter name: labelMatchInformation.TermLabel. So I obviously checked if I hadn't forgotten to set the TermLabelvariable. But the variable seemed fine: Showing TermLabel has been filled What am I missing here? I assume this is the right way to use GetTerms, it also seems like the only option for me here.

2 Answers 2


Here is my sample test code which works in my local, hope it would help you.

using (var ctx = new ClientContext("http://sp:12001/"))
                TaxonomySession taxonomySession = TaxonomySession.GetTaxonomySession(ctx);
                TermStore termStore = taxonomySession.GetDefaultSiteCollectionTermStore();
                    termStoreArg => termStoreArg.WorkingLanguage,
                    termStoreArg => termStoreArg.Id,
                    termStoreArg => termStoreArg.Groups.Include(
                        groupArg => groupArg.Id,
                        groupArg => groupArg.Name

                TermSet termSet = termStore.GetTermSet(new Guid("2bdf0a4e-9ff8-4db0-9f43-a9ea809d1b18"));
                //search for the Term to see if it exists
                LabelMatchInformation termQuery = new LabelMatchInformation(ctx)
                    TermLabel = "Developer Members",                   
                    TrimUnavailable = false
                var matchingTerms = termSet.GetTerms(termQuery);

                if (matchingTerms.Count <1)
                    Console.WriteLine("not found");

  • 1
    This code works, thanks a bunch. Could you explain to me though, what the crucial difference is here? (Compared to my example)
    – vonis22
    Sep 17, 2018 at 8:50

Two things.

  1. When you perform this query, you get that error message if you previously did changes to the termStore and did not explicitly call termStore.CommitAll(); ctx.ExecuteQuery();

  2. Docs state that only specific combinations of properties work:


The LabelMatchInformation values that are set MUST be one of these combinations:

LabelMatchInformation.TermLabel and LabelMatchInformation.TrimUnavailable.

LabelMatchInformation.TermLabel, LabelMatchInformation.Lcid, and LabelMatchInformation.TrimUnavailable.

LabelMatchInformation.TermLabel, LabelMatchInformation.DefaultLabelOnly, LabelMatchInformation.StringMatchOption, LabelMatchInformation.ResultCollectionSize, and LabelMatchInformation.TrimUnavailable.

LabelMatchInformation.TermLabel, LabelMatchInformation.Lcid, LabelMatchInformation.DefaultLabelOnly, LabelMatchInformation.StringMatchOption, LabelMatchInformation.ResultCollectionSize, and LabelMatchInformation.TrimUnavailable.

If the combination of LabelMatchInformation (section values is invalid, an ArgumentException or ArgumentNullException will be thrown indicating the invalid setting.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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