/ #debugging #Managed Metadata 

Managed Metadata Service unavailable first request after IISReset

Managed Metadata Service unavailable first request after IISReset header image

Last week I encountered an environment at a client that had some problems on their build automation scripts. Each night they would run a de-install and install of certain solutions, and for some reason it would always fail while installing. It looked like if the Managed Metadata Service was unavailable every first request after an IISReset, since the error shown was pretty straight forward:

TRACED: Exception: System.Exception: No termstore is found for site http://devexample

And since one of the features that was activated was running code against the Termstores, with code that looked like:

TaxonomySession session = new TaxonomySession(site, true);

if (session.TermStores.Count != 0)
    TermStore termStore = session.DefaultSiteCollectionTermStore;

    if (termStore != null)
        // Run code
        throw new Exception(string.Format("No DefaultSiteCollectionTermStore is found for site {0}", site.Url));
    throw new Exception(string.Format("No termstore is found for site {0}", site.Url));

It was obvious that the returned termstore count was 0, so we checked the usual:

  • Is the Taxonomy Service running
  • Is the Managed Metadata Service Application associated to the site
  • Does the webapplication account has access to it

But we after checking them all, it all looked okey, but we still had the issue. Now the ULS logs did not prove to be very useful since we couldn’t find anything useful there.  Then after fiddling around a bit with the issue, I could reproduce it using PowerShell. Each time we did an IISReset the first time we used code to retrieve the TaxonomySession there where 0 termstores found, knowing that I also found out that the first time we hitted the page for termstore management (/_Layouts/termstoremanager.aspx) it would also throw an error


So that got me to reanalyze the ULS logs again, since it’s in the UI it should be in the logs right… And there the I found a nice error:

Exception returned from back end service. System.TimeoutException: The request channel timed out while waiting for a reply after 00:00:29.9967885

So that lead me to search a bit more, and I stumbled upon a blog post about timeouts in the Managed Metadata Service Application. The timeout settings can be modified keeping in mind some reasonable setting according to MSDN. So I put the settings in my environement to 1 minute, and luckily for me that solved the issue that after an IISReset I could not access my termstore when using the UI.It also did fix my issue of not being able to retrieve any termstores from a session (Termstores.Count == 0), so if you ever get issues when retrieving the Termstores from a TaxonomySession (from code), and if you can not find anything in the ULS make sure there is no timeout. Something that can be done easy by using PowerShell to retrieve the termstores:

$site = Get-SPSite("someurl"); 
# passing a $true to update the cache, making sure we have a latest version
$session = new-object Microsoft.SharePoint.Taxonomy.TaxonomySession($site, $true); 
Loading comments…