This is a migrated thread and some comments may be shown as answers.

Another maxJsonLength Issue

3 Answers 650 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 06 Apr 2016, 05:03 AM

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

3 Answers, 1 is accepted

Sort by
0
Accepted
Nikolay Rusev
Telerik team
answered on 08 Apr 2016, 06:26 AM

Hello Andrew,

 

As you've already found there is a restriction of the size of JSON response imposed by the MVC framework. We have a section with advises for such scenarios. However a more appropriate solution will be to reduce the side of items being returned from server by either using enabling paging or virtualization.

 

You can find examples for this examples bellow:

 - Grid / Binding to remote data

 - Grid / Virtualization of remote data

 

Regards,
Nikolay Rusev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Joe
Top achievements
Rank 1
answered on 09 Jun 2017, 04:15 PM

For the time being, I removed the "All" option from the grid.  It's already using AJAX, and using a DataSourceRequest type in the MVC controller itself.  I didn't necessarily want the component to connect directly to the RESTful API, using the MVC controller for any additional data manipulation and validation required.  It's just one of the standards we enforce at our company, go through the MVC controller instead of directt o the API..

It's odd that the MVC controller can get all the data just fine from the API, but when passing it to the component that there's this limit.  Is there a way to overcome that limit? 

0
Joe
Top achievements
Rank 1
answered on 09 Jun 2017, 04:16 PM
Oops, ignore that, wrong message...
Tags
Grid
Asked by
Andrew
Top achievements
Rank 1
Answers by
Nikolay Rusev
Telerik team
Joe
Top achievements
Rank 1
Share this question
or