As anyone reading my blog, or watching WynApse.com knows, I went through a bunch of code putting an "OutlookBar" in Silverlight 1.0 onto the Right-hand sidebar of my MasterPage. It works great, it's been up and running in it's current version for quite a while and I keep adding items onto it. It's not as simple to add a whole new button, but I can do so through the database and then I'm off to the races again adding entries.
Maximum Length Exceeded
Until one day I got that
message... I had added a small link to one of the buttons, and when the page refreshed, it threw an error. I immediately backed the link out and then things were fine... hmmm... was it the menu was too big? I seem to remember putting *something* in the code to avoid that (I think)... So I tried a different button... same error. So I tried the text 'abc' and the link 'abc' ... still the error, so this is a tad more of a problem than I thought!
I'm much too busy for my own good right now, so it took a while until I was able to spin through the code and to my delight, the code is pretty tight... I remember spending a good part of a Saturday getting that running. And I don't see any length checking, and definitely that error message isn't from either my database layer or from the webservice.
I talked to Joel Neuberg at the last Phoenix Silverlight User's Group meeting and was suggesting that I was hitting some limit on CreateFromXAML... he said he's seen close to 5M of xml pushed into that. I had no idea how big my string was at the time.
I posed the question on the Insiders list and nobody bit on it, so I figured it was either something nobody cared about or they figured I was chasing a ghost.
Finally last night I took the time to capture the string prior to sending it through CreateFromXAML and found it is just under 99K, so much less than Joel's 5M. Plus I ran it through the 'beautifier' in SlickEdit, and that is some very nicely-formed XAML if I do say so... :)
So now what?
But, it still threw the error when I added 'abc'... so what was going on?
I finally smartened up a bit and realized the error message was not an alert box, it had an Internet Explorer caption, so it made me wonder if it had anything to do with the WebService, and maybe there is a maximum string length there. I mean, yeah the code is pretty and yeah the XML is pretty also, but I'm doing it all in one huge string... maybe it needs to be broken down into pieces.
Doing a search, I found this forum posting
that talks about maxJsonLength in web.config.
The exact code from web.config in WynApse.com looks like this:
<!-- Uncomment this line to customize maxJsonLength and add a custom converter -->
<add name="ConvertMe" type="Acme.SubAcme.ConvertMeTypeConverter"/>
As you can see above, my web.config looked identical to the one in the forum posting, and was commented out. I increased it to 400000, following my rule of thumb of pretty much always doubling anything I hit a limit on (and then some). I left the original line in just in case something didn't work, I'd know where it was when I began :)
I rebuilt it, pushed it to the site, and Hello Momma... it works just fine!
This is a great example of this fun business we're in... the error manifest itself while setting a menu entry into the database, so I naturally have assumed for over a month that it was a problem with some complicated XAML-producing code. Bottom-line, it had zero to do with the XAML, or the database code, or the webservice... it was all a commented-out line in my web.config!
I just thought I'd report this in case anyone else is trying to figure out something similar... might save a head-scratching session!