All posts

ScriptResource.axd and and assemblies built in the future

Here is something I didn't know until recently:

If you have a ScriptControl whose JavaScript files are web resources (served through ScriptResource.axd instead of WebResource.axd) and the date of the assembly is in the future, that very JavaScript file will fail to load.

I have attached a test solution to illustrate the case - AssemblyInTheFuture.zip. Build it and run the Default.aspx page - everything is fine and a nasty alert saying "initialize" pops out. Now change the date of your PC - set it to yesterday. Stop ASP.NET Development server to reset the script resource cache dependency. Open Default.aspx again (but DO NOT rebuild the project - let the ControlLibrary.dll be built in the future). Now a JavaScript error will occur saying that 'aStuff is undefined' or 'aStuff is not defined' if you are a FireFox guy (like yours truly). Firebug can immediately tell you why:



Here is the error in more user friendly format:


Specified argument was out of the range of valid values.
Parameter name: utcDate

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: utcDate

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: utcDate]
System.Web.HttpCachePolicy.UtcSetLastModified(DateTime utcDate) +3261043
System.Web.HttpCachePolicy.SetLastModified(DateTime date) +47
System.Web.Handlers.ScriptResourceHandler.PrepareResponseCache(HttpResponse response, Assembly assembly) +194
System.Web.Handlers.ScriptResourceHandler.ProcessRequest(HttpContext context) +1154
System.Web.Handlers.ScriptResourceHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext context) +4
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +154
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +64


Version Information: Microsoft .NET Framework Version:2.0.50727.42; ASP.NET Version:2.0.50727.213

A good thing to know is that the good old WebResource.axd does not depend on the time. You can try the following (in Default.aspx.cs):

    protected void Page_Load(object sender, EventArgs e)
    {
        Page.ClientScript.RegisterClientScriptResource(typeof(AjaxWebControl), "aStuff.AjaxWebControl.js");
    }

If you load the page a new JavaScript error will occur - "Type is undefined" which means that the file has been served successfully but is included before the core ASP.NET AJAX scripts.

In a word always make sure that you don't deploy assemblies which are built in the future :) This may  happen  if you deploy your web site on a server  in a different time zone.

And don't forget to restore your system date :)

Facebook DZone It! Digg It! StumbleUpon Technorati Del.icio.us NewsVine Reddit Blinklist Furl it!

Comments  8

  • 6 Jul, 08:51 AM

    I guess the Y2K Bug has nothing on the Time Travel Bug. :)

    I wonder if Marty and the Doc worked that out.

    Brennan Stehling

  • 10 Feb, 04:48 PM

    this could be considred as an asp.net bug

    ivo

  • 11 Mar, 10:56 AM

    Thanks so much for this post. My colleague and I had been scratching our heads about this after deploying to a server in the US, not having it work, and then it worked the next day! We thought we'd gone bonkers!

    Giles Hinton

  • 2 Apr, 11:56 AM

    Anyone have a satisfactory way to work around this, when handling deployments on servers across different time zones (including shifting to daylight-savings time)?

    Thanks.

    Hi

  • 3 Apr, 05:56 AM

    Changing the creation date of the files of my web appliction to a date in the paste on the server solved the probleme for me. (copying of the directory should do the trick).

    piter

  • 14 Apr, 10:07 AM

    You can use the "touch" utility to change the date of the assemblies (as we do internally).
    This command prompt script helps as well:
    "copy /b test.dll+,," (mind the two commas at the end).

    Atanas Korchev

  • 13 Nov, 06:01 AM

    Thanks! THis is something I definately wouldn't have been able to figure out without your help...

    Henric

  • 4 Dec, 08:50 AM

    I just wanted to thank you, after spending three days trying to understand why the webreource.axd was not working properly, finally i got the answer.







    Mi6uel

Post a comment!
  1. Formatting options
       
     
     
     
     
       
  2. Security image