ScriptResource.axd and and assemblies built in the future

by ASP.NET AJAX Team | Comments 11
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 :)

About the author

Stefan Rahnev

Stefan Rahnev

is the Unit Manager of the ASP.NET Telerik Division. He has been working for the company since 2005, when he started out as a regular support officer. His next steps at Telerik took him through the positions of Technical Support Director and co-team leader in one of the ASP.NET AJAX teams. Stefan’s main interests are web development, agile processes planning and management, client services and psychology.

11 Comments

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

I wonder if Marty and the Doc worked that out.
ivo
this could be considred as an asp.net bug
Giles Hinton
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!
Hi
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.
piter
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).
Atanas Korchev
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).
Henric
Thanks! THis is something I definately wouldn't have been able to figure out without your help...
Mi6uel
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.



damien
You're a genius - thanks! Save me heaps of time.
matt
Legend!! I had a VM in which the date was set to 6 months ago...when working with newer versions of sitefinity I had this same issue.

updating the date resolved it.

well done.
daniel
the "copy /b test.dll+,," solution worked also for me; we have a QA/PROD env where they set the servers dates 2/3months ago for testing.
thnx.

Comments

  1.    
      
      
       
  2. (optional, emails won't be shown on public pages)
  3. (optional)
Read more articles by ASP.NET AJAX Team - or - read latest articles in Developer Tools