Hello,
I have been researching solutions to this issue for some time now.
I am unable to rid myself of the error:
2016-04-06 14:27:24.0369, : Exception
(ControllerActionInvoker.InvokeExceptionFilters => HandlePageError.OnException => LSVLogger.LogException) 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 System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat)
at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj)
at System.Web.Mvc.JsonResult.ExecuteResult(ControllerContext context)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<
BeginInvokeAction
>b__1c()
at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<
BeginInvokeAction
>b__1e(IAsyncResult asyncResult)
I have tried many methods of trying to resolve this issue.
These include:
The solution outlined here: http://stackoverflow.com/questions/9943727/jsonmaxlength-exception-on-deserializing-large-json-objects whereby I add my own JsonValueProvider. This has not helped in my case.
I have tried the Web Config setting:
<
system.web.extensions
>
<
scripting
>
<
webServices
>
<
jsonSerialization
maxJsonLength
=
"2147483644"
/>
</
webServices
>
</
scripting
>
</
system.web.extensions
>
This also does not work.
I have tried simply overriding my ajax read methods default values:
public
ActionResult ExecuteQuery([DataSourceRequest] DataSourceRequest request, QueryRequestModel qParams)
{
DataTable queryResult = GetQueryData(qParams);
JsonResult jr =
new
JsonResult();
jr.MaxJsonLength =
int
.MaxValue;
jr.Data = queryResult.ToDataSourceResult(request);
using
(FileStream fs = System.IO.File.Open(@
"c:\LogFiles\ExecuteQuery1.json"
, FileMode.CreateNew))
using
(StreamWriter sw =
new
StreamWriter(fs))
using
(JsonWriter jw =
new
JsonTextWriter(sw))
{
jw.Formatting = Formatting.Indented;
JsonSerializer serializer =
new
JsonSerializer();
serializer.Serialize(jw, queryResult);
}
return
Json(jr);
//return Json(queryResult.ToDataSourceResult(request));
}
This also does not work.
Due to what our users are wanting to see, We are not paging the data. While the volume of data we are attempting to display is large (~27000 rows) it should be able to support what we are delivering.
A sample single row of the json (I wont provide a whole file, too big for forum upload) is:
{
"Type": "Credit",
"InvoiceNo": 1.0,
"Reference": "5",
"JobNo": " 99999",
"Branch": "010 ",
"Code": "SUN ",
"Dated": "2002-06-30",
"MonthNo": -156,
"Period": "2002-06",
"WeekNo": 27,
"NetValue": -708.00,
"GST": -70.80,
"GrossValue": -778.80,
"Account": " ",
"Client": "SUNDRY DEBTOR ",
"Created": null,
"CreatedBy": " "
},
If I narrow the query result considerably (By a factor of 100), This does in fact work. (I can view 270 rows, 27000 kicks it)
Any help would be appreciated, as I feel like we have now exhausted all options in trying to solve this issue.
The ideal solution would be to allow for this accommodate any data volume. We are building an intranet based application and issues that may be limiting factors on Internet websites, don't really bother us for our little financial queries intranet site.
For completion sake, My grid partial view looks like:
@model System.Data.DataTable
@(Html.Kendo().Grid<
dynamic
>()
.Name("queryResultGrid")
.Sortable()
.Groupable()
.Selectable()
.Scrollable()
.Filterable()
.Reorderable(reorder => reorder.Columns(true))
.Resizable(resize => resize.Columns(true))
.DataSource(dataSource => dataSource
.Ajax()
.Model(model =>
{
foreach (System.Data.DataColumn column in Model.Columns)
{
var field = model.Field(column.ColumnName, column.DataType);
}
})
.Read(read => read.Action("ExecuteQuery", "Query") // Set the action method which will return the data in JSON format
.Data("prepareQueryParams") // Specify the JavaScript function which will return the data
)
)
)
Again any help appreciated. Telerik or community alike.
Thanks,
Andrew