MaxJsonLength property with Nancy

You might have some fun like me trying to figure out what’s going on when everything looks fine from server side, but an internal error occured before it reaches your client side, with a message like: Nancy.Json.JsonSettings.MaxJsonLength Exceedednancylogo-transparent

As you can suppose, you have to either reduce the size of your object, or (more likely) to increase the max json length that your server can transfer to your client.

The trick is that if you are just looking for MaxJsonLength Exceeded on Google, you will find lot’s of answers for ASP.NET which basically consist of a new line in your web.config.

But if you want to make it works with Nancy, you have to write (Of course you can replace Int32.MaxValue by a more decent value):

JsonSettings.MaxJsonLength = Int32.MaxValue

Put it anywhere in the initialisation of your server (I personally do it in my bootstrapper class). And do not write anything about json size in your web.config because Nancy just does’nt care.

Have fun!

 

 

Ouarzy

 

Leave a Reply

Your email address will not be published. Required fields are marked *

IP Blocking Protection is enabled by IP Address Blocker from LionScripts.com.