Workaround: The length of the string exceeds the value set on
the maxJsonLength property in SharePoint 2013 list forms
18 July 2014
I was getting this error when I opened a SharePoint list display/New forms. The error appears when I was doing load/scalability testing of SharePoint list with lot of data. The main list has couple of lookup columns. The size of lookup lists was big (around 20K items in each list which was referenced as lookup in the main list )
When I try to load New/Display form of main list, a variable called WPQ2FormCtx gets loaded with all lookup lists titles and ID in page view source.
Problem: The WPQ2FormCtx variable exceeds the maxJsonLength property which was set in web.config.
This context is somehow new in SharePoint 2013 and Office 365. This somehow represents the so called form context with a lot of information. Also included in this WPQ2FormCtx variable is the list schema which we can use without loading any additional information from the list.
ULS Error:
System.InvalidOperationException: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat)
at Microsoft.SharePoint.WebControls.ClientFormManager.OnPreRender(EventArgs e)
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Control.PreRenderRecursiveInternal()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
Attempt to resolve this issue:
I tried to change the maxJsonLength property in web application web.config file, which does not resolve the issue because this poetry only works if you create your own Serialize object like this.
JavaScriptSerializer serializer = new JavaScriptSerializer();
Workaround to resolve this issue:
I had to update list schema <forms> section and add UseLegacyForm=”TRUE” attribute for my new/edit and display forms. This will stop the auto creation of WPQ2FormCtx variable when you load your form.
<Forms>
<Form Type=”DisplayForm” Url=”DispForm.aspx” SetupPath=”LAYOUTS\SCI.AMS\Pages\List1DisplayForm.aspx” UseLegacyForm=”TRUE” WebPartZoneID=”Main” />
<Form Type=”EditForm” Url=”EditForm.aspx” SetupPath=”LAYOUTS \Pages\List1EditForm.aspx” UseLegacyForm=”TRUE” WebPartZoneID=”Main” />
<Form Type=”NewForm” Url=”NewForm.aspx” SetupPath=”LAYOUTS\SCI.AMS\Pages\List1NewForm.aspx” UseLegacyForm=”TRUE” WebPartZoneID=”Main” />
</Forms>
Msdn definition of “UseLegacyForm” attribute: Used during upgrade to specify that Microsoft SharePoint Foundation use Collaborative Application Markup Language (CAML), as in previous versions of the technology, instead of Web controls, to define the view of an item within a form.
Important: This only works if you have built custom aspx list forms. The OOTB SharePoint 2013 list are not supported in this scenario.