0

I have an application that's been in production for a while - it's written in c# on dotnet framework 4.5 using MVC 4.

Some of it's screens are simple things that allow edit of small data sets - they are written using knockoutjs and the whole data-view is sent to the server, edited and then downloaded again so that knockout can rebind it.

The problem started this week. The delete function won't work anymore. On debugging I found that the function wasn't being hit. By debugging in Fiddler, I have been able to remove records, and found that 83 record load, 84 or more records don't.

I thought that this was request size, but that's only 24Kbytes - I upped the MaxRequestLength to a good few megabytes to make sure - still fails.

By hollowing out the function and removing the bound parameter, the behavior doesn't change. But if I remove "Content-Type: application/json" header, all of the data uploads and my function can be hit - this suggests to me that MVC 4 parses JSON requests based on mime type whether there is a bound parameter or not, and that the JSON parser has a maximum length or complexity configuration.

Thinking about complexity, I stripped the 84th record down to just it's ID, and then I managed to receive 84 records - I can remove properties from objects from any object in the JSON and it can load the 84th record, but I can't remove bytes from descriptions etc. It's almost as if I loaded more JSON properties than MVC 4 allows, but that seems very odd to me.

Does anybody know if this is a known fault with a known workaround? Or if there are settings to control how the JSON parser works in MVC 4?

--EDIT--

Our Raygun facility managed to get an exception report that didn't come up with the debugger attached:

ERROR Uncaught MVC error System.InvalidOperationException: The JSON request was too large to be deserialized. at System.Web.Mvc.JsonValueProviderFactory.EntryLimitedDictionary.Add(String key, Object value) at System.Web.Mvc.JsonValueProviderFactory.AddToBackingStore(EntryLimitedDictionary backingStore, String prefix, Object value) at System.Web.Mvc.JsonValueProviderFactory.AddToBackingStore(EntryLimitedDictionary backingStore, String prefix, Object value) at System.Web.Mvc.JsonValueProviderFactory.AddToBackingStore(EntryLimitedDictionary backingStore, String prefix, Object value) at System.Web.Mvc.JsonValueProviderFactory.AddToBackingStore(EntryLimitedDictionary backingStore, String prefix, Object value) at System.Web.Mvc.JsonValueProviderFactory.GetValueProvider(ControllerContext controllerContext) at System.Web.Mvc.ValueProviderFactoryCollection.<>c__DisplayClassc.b__7(ValueProviderFactory factory)

  • the stack trace goes on and on, so I haven't included it all.

Thanks.

Mark Rabjohn
  • 1,643
  • 14
  • 30
  • Do you have any ampersands `&` in a property of one of the objects? Default max json size is 100kbs so I don't think you have an issue with the size. – Ryan Wilson Jan 29 '21 at 16:10
  • I'm assuming the json is not hand-crafted using string concatenation or whatnot? It's built by using a json serializer library? – Lasse V. Karlsen Jan 29 '21 at 16:11
  • The Json was made in Javascript via JSON.stringify - I've found an exception now - a cear indication that the JSON is too compex for dotnet 4.5's JSON converter! It's actually only three arrays of objects and the list that is populated has 100 record with only 12 intrinsic properties each. – Mark Rabjohn Jan 29 '21 at 17:46
  • 1
    @MarkRabjohn The exception message is clear, try giving this a read (https://stackoverflow.com/questions/43539106/the-json-request-was-too-large-to-be-deserialized-mvc-knockoutjs) or this (https://stackoverflow.com/questions/10966328/getting-the-json-request-was-too-large-to-be-deserialized) for a solution, you changed the `MaxRequestLength` in config but this is a different property `aspnet:MaxJsonDeserializerMembers` that must be increased in the config file or on controller method. – Ryan Wilson Jan 29 '21 at 17:49
  • @RyanWilson - I didn't hit those when I searched. I've already changed my program to upload less data, but this looks to be the setting that I was missing, I'll remember it in the future, thanks. – Mark Rabjohn Feb 01 '21 at 10:12
  • @MarkRabjohn You're welcome. So did changing that in the config fix it? Just making sure that changing the config property above was the solution. – Ryan Wilson Feb 01 '21 at 13:14
  • I'd already updated my program to upload the single record that was required for the action - the action then reloads the full dataset to refresh, so I didn't need the setting - I did read the Microsoft docs on it now I know what it's called, and I believe that it would have also fixed my problem. – Mark Rabjohn Feb 03 '21 at 15:35

0 Answers0