0

When try to posing a huge json to my site (includes a big image) I get the following error:

Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property

All answers on SO and the web show basically 2 options:

  1. Use a setting in code on the JsonSerializer, which is irrelevant here, since I have no code. The error happens much before my action is called.

  2. set the maxJsonLength in the web.config. which I did. but to no avail. I believe its relevant only to WebServices. which is not my case

For good measure I also increased my MaxJsonDeserializerMembers

Here's the relevant parts of my web.config:

<configuration>
<appSettings>
<add key="aspnet:MaxJsonDeserializerMembers" value="2147483647" />
</appSettings>
<system.webServer>
<security>
  <requestFiltering>
    <requestLimits maxQueryString="32768" maxAllowedContentLength="40000000" />
  </requestFiltering>
</security>
</system.webServer>
<system.web>
<httpRuntime maxRequestLength="7864320" requestValidationMode="2.0"
  maxQueryStringLength="11000" targetFramework="4.7.2" />
</system.web>
<system.web.extensions>
<scripting>
  <webServices>
    <jsonSerialization maxJsonLength="2147483647" />
  </webServices>
</scripting>
</system.web.extensions>
</configuration>

Still the same error.

If it makes any difference, I'm posting with fetch.

Here is the StackTrace:

at System.Web.Script.Serialization.JavaScriptSerializer.Deserialize(JavaScriptSerializer serializer, String input, Type type, Int32 depthLimit) at System.Web.Mvc.JsonValueProviderFactory.GetDeserializedObject(ControllerContext controllerContext) at System.Web.Mvc.JsonValueProviderFactory.GetValueProvider(ControllerContext controllerContext) at System.Web.Mvc.ValueProviderFactoryCollection.GetValueProvider(ControllerContext controllerContext) at System.Web.Mvc.ControllerBase.get_ValueProvider() at System.Web.Mvc.ControllerActionInvoker.GetParameterValue(ControllerContext controllerContext, ParameterDescriptor parameterDescriptor) at System.Web.Mvc.ControllerActionInvoker.GetParameterValues(ControllerContext controllerContext, ActionDescriptor actionDescriptor) at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass3_1.b__0(AsyncCallback asyncCallback, Object asyncState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.Begin(AsyncCallback callback, Object state, Int32 timeout) at System.Web.Mvc.Async.AsyncControllerActionInvoker.BeginInvokeAction(ControllerContext controllerContext, String actionName, AsyncCallback callback, Object state) at System.Web.Mvc.Controller.<>c.<BeginExecuteCore>b__152_0(AsyncCallback asyncCallback, Object asyncState, ExecuteCoreState innerState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid1.CallBeginDelegate(AsyncCallback callback, Object callbackState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.Begin(AsyncCallback callback, Object state, Int32 timeout) at System.Web.Mvc.Controller.BeginExecuteCore(AsyncCallback callback, Object state) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.Begin(AsyncCallback callback, Object state, Int32 timeout) at System.Web.Mvc.Controller.BeginExecute(RequestContext requestContext, AsyncCallback callback, Object state) at System.Web.Mvc.MvcHandler.<>c.b__20_0(AsyncCallback asyncCallback, Object asyncState, ProcessRequestState innerState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid1.CallBeginDelegate(AsyncCallback callback, Object callbackState) at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase1.Begin(AsyncCallback callback, Object state, Int32 timeout) at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state) at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

What else can I do?

Thanks!

Yisroel M. Olewski
  • 1,560
  • 3
  • 25
  • 41
  • I've duplicated this to a question you may have read, but it genuinely is the same problem. I've not seen anything like this for a long time, it looks like you are using an old version of .NET Framework rather than .NET Core. You could possibly get around it by manually deserialising in the controller method by using a "decent" JSON library like Newtonsoft instead of `JavaScriptSerializer` which is never used any more. – DavidG Feb 03 '21 at 10:22
  • It is not the same problem. As I clearly stated. My issue is with sending large json. There it's with receiving. I have no control of the the Deserialize. The satckTrace is entirely internal in .net. – Yisroel M. Olewski Feb 03 '21 at 10:34
  • @DavidG Please reopen my question. I have read that question. it is about serializing in code for sending to client. I am referring to DEserializing. and no code control. It is somewhere in the Asp.Net engine. I cannot use any library I want. Thanks. – Yisroel M. Olewski Feb 08 '21 at 08:45

0 Answers0