System.ArgumentOutOfRangeException at System.Web.HttpCachePolicy.UtcSetLastModified (DateTime utcDate)

I spent most of yesterday configuring a server, then delving into the aforementioned error with a few other devs. Here is basically what we did to figure it out, and what the cause was.

The error

The day started by setting up a new server, and getting our ASP.NET application up and running. At first, the error wasn’t apparent. It was when we started seeing javascript errors on different pages. It looked as though one javascript includes was causing the error, /WebResource.axd?d=KadOK03KouGAGUGwjTWw4w2&t=633707613869062500.

When pulling up the included javascript file directly in the browser, the full error was seen.

       Type : System.ArgumentOutOfRangeException, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
       Message : Specified argument was out of the range of valid values.
Parameter name: utcDate
       Source : System.Web
       Help link :
       ActualValue :
       ParamName : utcDate
       Data : System.Collections.ListDictionaryInternal
       TargetSite : Void UtcSetLastModified(System.DateTime)
       Stack Trace :    at System.Web.HttpCachePolicy.UtcSetLastModified(DateTime utcDate)
          at System.Web.Handlers.AssemblyResourceLoader.System.Web.IHttpHandler.ProcessRequest(HttpContext context)
          at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
          at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

The problem

Google quickly helped me figured out what was causing it, some assemblies were dated in the future.

I was a little confused as to why though. I looked at the timestamp portion of the request, to see what its value was, /WebResource.axd?d=KadOK03KouGAGUGwjTWw4w2&t=633707613869062500.

PS C:\> new-object DateTime 633707613869062500
 
Friday, February 20, 2009 9:16:26 PM
 
PS C:\> [DateTime]::Now
 
Friday, February 20, 2009 1:21:22 PM

So the assembly trying to be loaded is ~8 hours in the future, not good.

Who is causing the problem?

Now I know what the problem is, but looking through all the DLL’s for timestamp problems could take forever. Powershell to the rescue.

gci -recurse | where { $_.LastWriteTime -gt [DateTime]::Now }

I ran this on the application directory, then C:\Windows\Microsoft.NET, then C:\Windows\assemblies.

Bam. The problem was in C:\Windows\Microsoft.NET and C:\Windows\assemblies.

(Side note: Smarty pants Lamar showed this could be done with just Windows search and ordering by the date column.)

My first idea

Can I change the LastWriteTime of a file?

PS C:\> gi c:\ | get-member LastWriteTime
 
   TypeName: System.IO.DirectoryInfo
 
Name          MemberType Definition
----          ---------- ----------
LastWriteTime Property   System.DateTime LastWriteTime {get;set;}

Yes, there is a setter!

gci -recurse | 
  where { $_.LastWriteTime -gt [DateTime]::Now } | 
  %{ $_.LastWriteTime = [DateTime]::Now }

Well, that worked for C:\Windows\Microsoft.NET, but not C:\Windows\assemblies since all the DLLs in there are in use.

The final solution

Reinstall .NET framework, entirely. I know, you were expecting something amazing, and I failed you. Well, sorry. I was annoyed too, but it was the easiest way I could think accomplish the task. What is important is how I was able to use Powershell to test out different scenarios and possible solutions. If I would have had to write a command line program in Visual Studio to figure out what different timestamp values actually were, I wouldn’t have done it.

The other question you might have is why were times so off? Well, the server was a fresh install and the time wasn’t set properly for some reason. .NET was installed before checking the time that was set. This would have been fine, but the server was added to the AD domain, which quickly changed the time to the correct time.

Powershell? Yes

I have read over Scott Hanselman’s Tool List at least a dozen times. The first time I read it, I saw that Powershell was on his top 10. I knew a little about Powershell from Exchange 2007 but hadn’t taken any time to look at it.

About a month ago, I had to write some server maintenance scripts. Things like deleting files older than X days, SQL Server maintenance, etc. These tasks were perfect for scripting, so I picked up a Powershell book and went to town. It took a while to pick it up, but my overall impression of Powershell is wow. Powershell fills that void in the soul of Windows that developers hate. Now scripting in Windows doesn’t have to involve Cygwin and Perl, even though Perl will always stay close to my heart.

Powershell combines the ease of scripting with the power of .NET. It is a loosely typed language that can work with strongly typed objects from .NET. For me, it boils down to scripting objects instead of text. In Bash, grep and awk had to be used when parsing the output of any program. In Powershell, the output of a program is usually an object, which is much easier to work with.

The following line sums up why I love Powershell. It deletes files older than 14 days in a directory. While this is a trivial example, it is so simple, and so elegant.

gci c:\directory |  where { $_.LastWriteTime.AddDays(14) -lt [DateTime]::Now } | ri

Amazon Unbox + XBox = Joy; Goodbye Ubuntu

Yesterday I found this gem of an article on Amazon’s website. I wish I had known about it sooner.

I got home, and immediately tried it out. After about 1 minute, I was watching an on-demand video on my TV, through my XBox. Before, I thought I had to go through a VGA cable directly from my laptop, which is a pain. This is much better.

The quality isn’t HD; it looks to be about DVD quality. Even still, I think it is enough for me to cancel my satellite subscription and be completely on-demand. I only watch 2 TV shows, and the rest just waste my time. If only Discovery and History channels streamed over the internet, I wouldn’t miss satellite at all.

Also, I think this is the catalyst to get me to ditch my Ubuntu desktop for a Windows machine. Being able to easily have on-demand video is a perk like none other. At long last, I have given up what I so fell in love with a few years ago. I am sure this isn’t are last meeting, goodbye Ubuntu.

Restarting Terminal Services

A common problem with Windows servers is remoting. Unless you pay a large amount of money, you can only have two terminal services connections per server for administration purposes. Sometimes people leave the office and accidentally stay connected, which ties up a connection and means no one else can connect.

Since most of our development and live servers are accessed remotely, this quickly becomes a big problem. Luckily, I found an article that can help in this situation. I know any Windows sysadmins out there have probably known about this for a long time, but I haven’t. Since I am in charge of a few development servers, I need to know these tricks.

UPDATE: Much better advice from Sebastian.

Hi Brian,
I’m a Windows and Linux enterprise admin and software developer.
tsshutdn will restart the server. Instead you can just ask who’s connected executing “quser /server:YOURSEVER” from another terminal server.
Once you have the current sessionID numbers on the server, you can log them out with the command:
“logoff /server:YOURSERVER SESSIONID”.

I hope this helps you.
regards,
Sebastian.



tsshutdn <wait_time> /server:<server_name> /reboot /delay:<log_off_time> /v

This will disconnect everyone remotely connected and then reboot terminal services.

Remote Desktop on Windows Server 2003 R2 SP2

Over the past few years, I have installed Windows Server on a handful of our development machines. Every time, I follow the same steps except it didn’t work to well this time.

Somewhere in the mix of releases and service packs, a major naming change occurred that I had no idea about. In previous versions, to enable remote desktop, I would just install terminal services which would run in administrative mode by default. This allowed 2 simultaneous connections from administrators which is what I needed.

When I installed terminal services this time, it ran for 120 days and then proceeded to stop accepting connections because it required a licensing server. It was obviously not running in administrative mode. What I soon realized was, terminal services in administration mode is now called remote desktop for administration. Instead of being part of terminal services, it is now separate which means it is installed differently.

To get it up and working, just follow this simple guide.