yodeski / mvc-mini-profiler

Automatically exported from code.google.com/p/mvc-mini-profiler
0 stars 0 forks source link

Server side error thrown if the profile trace gets over 4MB (2,097,152 characters) #104

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
We have a few pages with complex SQL operations and lots of profiled steps, 
when we attempt to profile these pages we get an error:

[InvalidOperationException: Error during serialization or deserialization using 
the JSON JavaScriptSerializer. The length of the string exceeds the value set 
on the maxJsonLength property.]
   System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat) +924778
   MvcMiniProfiler.MiniProfiler.ToJson(MiniProfiler profiler) in C:\Users\sam\Desktop\mvc-mini-profiler\MvcMiniProfiler\MiniProfiler.cs:494
   MvcMiniProfiler.UI.MiniProfilerHandler.Results(HttpContext context) in C:\Users\sam\Desktop\mvc-mini-profiler\MvcMiniProfiler\UI\MiniProfilerHandler.cs:204
   MvcMiniProfiler.UI.MiniProfilerHandler.ProcessRequest(HttpContext context) in C:\Users\sam\Desktop\mvc-mini-profiler\MvcMiniProfiler\UI\MiniProfilerHandler.cs:133
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +625
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +270

We can get by this in our own code with a config setting (See more at 
http://msdn.microsoft.com/en-us/library/bb763183.aspx):
<configuration>
  <system.web.extensions>
    <scripting>
      <webServices>
        <jsonSerialization maxJsonLength="2147483647"/>
      </webServices>
    </scripting>
  </system.web.extensions>
</configuration>

However the mini profiler seems to ignore this, probably because it's using the 
Javascript serialiser directly.

I think the fix is to change line 394 of \MvcMiniProfiler\MiniProfiler.cs from

    var result = new JavaScriptSerializer().Serialize(profiler);

To

    var result = new JavaScriptSerializer{ MaxJsonLength = int.MaxValue }.Serialize(profiler);

I've applied this fix to a clone at 
http://code.google.com/r/keithhenry-bugfixes/source/detail?r=7fd4635ed41cd195ee1
9b924ee6c2cbf1799294f

Original issue reported on code.google.com by keithhe...@gmail.com on 2 Sep 2011 at 8:43

GoogleCodeExporter commented 9 years ago
Also as a patch: http://code.google.com/p/mvc-mini-profiler/issues/detail?id=106

Original comment by keithhe...@gmail.com on 5 Sep 2011 at 7:39

GoogleCodeExporter commented 9 years ago
I'm experiencing the same issue, do you know when the update will be available 
at NuGet

Original comment by marko.hu...@gmail.com on 20 Sep 2011 at 4:51

GoogleCodeExporter commented 9 years ago
When Sam updates it I guess, but you can download the patch to your own copy in 
the meantime.

Original comment by keithhe...@gmail.com on 20 Sep 2011 at 9:09

GoogleCodeExporter commented 9 years ago
fixed it now 

Original comment by sam.saff...@gmail.com on 14 Feb 2012 at 4:54

GoogleCodeExporter commented 9 years ago
Is this really fixed? 
I just get the same exception with the current release.
From the elmah log:

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 StackExchange.Profiling.MiniProfiler.ToJson(MiniProfiler profiler) in C:\Users\sam\Desktop\MiniProfiler\StackExchange.Profiling\MiniProfiler.cs:line 374
   at StackExchange.Profiling.UI.MiniProfilerHandler.Results(HttpContext context) in C:\Users\sam\Desktop\MiniProfiler\StackExchange.Profiling\UI\MiniProfilerHandler.cs:line 302
   at StackExchange.Profiling.UI.MiniProfilerHandler.ProcessRequest(HttpContext context) in C:\Users\sam\Desktop\MiniProfiler\StackExchange.Profiling\UI\MiniProfilerHandler.cs:line 131
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

Original comment by aprja...@gmail.com on 20 Dec 2012 at 9:33

GoogleCodeExporter commented 9 years ago
I can confirm it's not fixed in 2.0.4

Original comment by zombie.c...@gmail.com on 28 Dec 2012 at 8:26

GoogleCodeExporter commented 9 years ago
Same here. Getting the error in the MiniProfiler version that's currently on 
nuget (published June 2012). 

Original comment by gisc...@gmail.com on 5 Feb 2013 at 8:11

GoogleCodeExporter commented 9 years ago
The default is set to 2097152 characters in MiniProfiler.Settings.cs

But you can override this with something like:

MiniProfiler.Settings.MaxJsonResponseSize = 2147483647

Original comment by ianfrase...@gmail.com on 25 Feb 2013 at 3:50