Expanding a SharePoint term group is throwing the error 'There was an error processing the request'

One of our customers was experiencing a very complex issue; whereas, when they expand a managed metadata term group, they get the error "There was an error processing the request", as shown below:

 

 

This issue was happening on their SharePoint 2016 farm; whilst this MMS DB was migrated from their SharePoint 2013 farm. Shockingly, this issue was not persistent on their SharePoint 2013 farm. Moreover, the issue was with only one term group!

 

Digging deeper in this, we found the below response using Fiddler while reproducing the issue:

 

 

From the above trace, this error is happening when making the JSON call ".../_vti_bin/taxonomyinternalservice.json/GetTermSets". Therefore, I had a look on the generated SharePoint VerboseEx logs, and found nothing there, but sending the response 500, as shown below:

 07/31/2017 12:45:59.22 w3wp.exe (0x1AE8) 0x15D0 SharePoint Foundation Runtime aoxsq Medium Sending HTTP response 500 for HTTP request POST to https://sp2016:10505/_vti_bin/taxonomyinternalservice.json/GetTermSets d7a60a9e-e1ab-808f-0000-0eafeb52869f

In order to identify if this is related to the JSON call itself, or stored data on the MMS DB, I retrieved the same Term sets for this term group using the below PowerShell code, which ran successfully without any problems!

 $taxonomySite = get-SPSite “CA Site URL”

$taxonomySession = Get-SPTaxonomySession -site $taxonomySite

$termStore = $taxonomySession.TermStores["MMS Proxy Name"]

$group = $termStore.Groups | ?{$_.Name -like "Term Group Name"}

$group.TermSets 

N.B., ensure changing the above highlighted values with yours

Digging deeper, I noticed that the issue will be resolved when deleting some of the returned term sets. Hence, this is a sizing issue. Therefore, I increased the JSON data size by adding the below snippet of code in the web.config file located at "C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\16\isapi"; right beneath the closing tag "</system.web>".

 <system.web.extensions>

    <scripting>

      <webServices>

        <jsonSerialization maxJsonLength="900000" />

      </webServices>

    </scripting>

</system.web.extensions>

 

So, the web.config file is going to be as follows

 <configuration>
  <system.web>      
        <webServices>
            <protocols>
                <remove name="HttpGet" />
                <remove name="HttpPost" />
                <remove name="HttpPostLocalhost" />
                <add name="Documentation" />
            </protocols>
        </webServices>
        <customErrors mode="On"/>
    </system.web>
<system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="900000" />
      </webServices>
    </scripting>
 </system.web.extensions>
    <location path="authentication.asmx">

 

Hereafter, I restarted IIS which resolved the issue for good!

P.S., if you have more than one SharePoint server, don't forget to apply this fix on all your SharePoint servers