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).

9 comments:

  1. I was having the same problem. I was able to relate my problem directly to this bug in the ToolkitScriptManager.

    http://ajaxcontroltoolkit.codeplex.com/workitem/26843

    somehow Http 1.1 got turned off on my IE settings. But the real issue is infact a bug in theToolkitScriptManager.

    ReplyDelete
  2. Rob - this worked perfectly for me, I had exactly the same problem as you, where the issue was only happening in IE and only for certain users. I searched the web for nearly 2 days looking for an answer until I found yours. Great work! Thank you.

    ReplyDelete
  3. Rob, You are a gentleman and a scholar. I have been so frustrated by this bug for months now. It is quite amazing that you posted this about a year and a half ago and the Ajax Toolkit still has not fixed this bug. (On second thought is it really amazing they are not dealing with it?) Again, you are awesome for posting this fix. Kudos to you.

    ReplyDelete
  4. YESSSSSS!!! LOVE U MAN!






    This WORKS!!! But i got another error. I must add this: CombineScripts="false" in the ToolkitScriptManager

    Thank you!
    Huge form Argentina!

    ReplyDelete
  5. Lucas estoy teniendo el mismo problema, podrias masarme tu gtalk asi me comentas. Te agradeceria un monton!

    ReplyDelete
  6. I just solve the problem, thank you so much!

    ReplyDelete
  7. Worked for me as well, Thanks a lot

    ReplyDelete
  8. Thanks a lot you have saved my day. Struggling from past 2 days.

    ReplyDelete