Sharepoint 2013 - Taxonomy- Microsoft.SharePoint.Taxonomy.TaxonomySession.GetTaxonomySession”

csom, sharepoint-2013, taxonomy

Solution

credit to user1545314 and google

Problem

I am updating manage meta data field using C#. Following is code to get TermId for term. ``` string termId = string.Empty; try { TaxonomySession tSession = TaxonomySession.GetTaxonomySession(CC); TermStore termStore = taxonomySession.GetDefaultSiteCollectionTermStore(); TermSet tset = ts.GetTermSet(termSetId); // I have proper Guid here, checked this in SharePoint 2013 server. LabelMatchInformation lmi = new LabelMatchInformation(CC); lmi.Lcid = 1033; lmi.TrimUnavailable = true; lmi.TermLabel = "xyz"; //Name of the term. TermCollection termMatches = tset.GetTerms(lmi); CC.Load(tSession); CC.Load(ts); CC.Load(tset); CC.Load(termMatches); CC.ExecuteQuery(); if (termMatches != null && termMatches.Count() > 0) termId = termMatches.First().Id.ToString(); } catch (Exception ex) { var d = ex.Message; } return termId; } ``` But I am getting exception as: “Cannot invoke method or retrieve property from null object. Object returned by the following call stack is null. \"GetDefaultSiteCollectionTermStore\r\nMicrosoft.SharePoint.Taxonomy.TaxonomySession.GetTaxonomySession”. I have tried to load manually from Sharepoint2013, it works fine there. Is there anything missing ? Thanks for help..

Original source