Monday 15 February 2010

Invalid character error from ScriptResource.axd

Ok so I had this weird 'Sys is undefined' error in ASP.Net Ajax client side scripts.

It was only happening in IE which was a bit frustrating and only for certain users so I had a sneaking suspicion that it was a client side issue.

Since this is such a generic error (loosely translated to 'it didn't work') there are many posts and suggestions about this plastered over the forums, unfortunately none that I found seemed to solve my problem so I had to resort to trying to figure it out for myself.

After tying myself in knots trying to work out what was going on I finally stumbled on the solution to my particular issue. It turned out that (for me anyway) it was a combination of a couple of problems. Firstly I had to turn off ScriptCombining on the ToolkitScriptManager (again it worked fine for me but not for all users), AND I also had to turn off script compression.

IE didn't seem to be able to decompress the scripts client side and so was bailing out at the first character.

For reference, to disable compression it was this quick entry in the web.config file.

<system.web.extensions>
<scripting>
<scriptResourceHandler enableCompression="false" enableCaching="true"/>
</scripting>
</system.web.extensions>

So, if IE is giving you random loading errors for your Ajax.Net scripts, try disabling compression, and/or turning off CombineScripts (its on by default so you will have to specifically set it to false).