.NET Framework 1.1 Service Pack 1 and Page.RegisterStartupScript

First, if you are are developing exclusively ASP.NET 2.0+ applications, sorry, there is nothing interesting for you in this post.

Second, if you are involved in some ASP.NET 1.1 projects and have no plans to install new development environment, then, sorry again, there is probably no reason for you to read on either. Ok, I've done all I could to warn you against reading it. Don't blame me for wasting you time, because I am going to start from the very beginning.

One of my current projects is ASP.NET 1.1 Web Application. It is already released and rather stable. And yesterday I got new development machine on my workplace and migrated all my data to it. .NET Frameworks 1.1, 2.0, 3.0, 3.5 were preinstalled before I first logged in (thanks to our system administrators). I installed VS 2003 and SP1 for it, VS 2008, SVN client, some other necessary utilities and components. Then, updated sources from source control for the mentioned ASP.NET 1.1 Web Application and started it. Bang! Script error - some variable is undefined.

Actually there were a bunch of such errors on the page. As I intentionally mentioned earlier, the application is stable. And this particular page was not changed for quite some time.

Brief research of the generated HTML source, code-behind class and respective web controls revealed the cause of the exception: there was a sequence of similar Page.RegisterStartupScript statements which went in pairs. The first one in a pair registered some JavaScript object, and the second one - used the object in another declaration.

First I checked source control's log - no related changes. Then, the next suspect - application configuration changes that could cause such behavior. But no, all the related controls' declarations on the page are static.

Ok, code was not changed, application is working fine on QA environment. So, something is wrong with my new machine. But what? 

I had a dim recollection that there is something wrong with the sequence of script registration in ASP.NET 1.1. But common sense told me that if something wrong could happen then it would had happened long ago.

Still, I opened Reflector and found such code inside RegisterScriptBlock method of System.Web.UI.Page class:

     if (scriptBlocks == null)
        scriptBlocks = new HybridDictionary();

As you probably well aware of, HybridDictionary changes its internal storage from ListDictionary to Hashtable starting from its ninth element. So, of course we cannot rely on any specific order of script registrations if script blocks are stored in HybridDictionary. But how did it work earlier and how the same code works on development server and QA environment without any bugs reported? 

So, I copied Reflector to the development server and found following code in the same RegisterScriptBlock method that I reviewed on my machine:

    if (scriptBlocks == null)
        scriptBlocks = new ListDictionary();

The code was fixed. But where did the fix come from? I recalled that there is a service pack for .NET 1.1 that I installed on my old development machine several years ago. Google promptly gave me a link.

File name: NDP1.1sp1-KB867460-X86.exe, Version: 1, Date Published: 8/30/2004, Download Size: 10.2 MB

Why am I presenting all this information here? Because the fix did not help, though I was almost certain that it should. The same HybridDictionary.

That's was fiasco. My working day was over several hours ago. Finish.

But today I decided to reproduce the issue at home. Fortunately I had a virtual machine with Windows XP and fortunately the copy of .NET 1.1 System.Web.dll had the same version as the one at work (i.e. HybridDictionary is used in RegisterScriptBlock).

So I started googling again and found the second service pack. Strangely enough it has the same name (i.e. .NET Framework 1.1 Service Pack 1) though with a lengthy suffix (.NET Framework 1.1 Service Pack 1 SYSTEM.WEB.DLL and MSCOREE.DLL Security Update for Windows 2000, Windows XP, Windows 2003 Server x64/IA64 and Windows 2003 Server R2 x64/IA64) .

Like the previous service pack that I found, description for this one states that its purpose - security improvements. No mentions of ASP.NET-specific modifications. I could not find any documentation which describes the changes in detail.

But the main thing is that this second "Service Pack 1" done what I wanted. Eventually I had my ListDictionary back.

The summary is:

1) there are at least TWO patches called ".NET 1.1 Service Pack 1";

2) both of them state that they are focused on security improvements, but

3) one of them changes at least one fundamental aspect of ASP.NET 1.1 behavior. 

Thank you for reading. Good luck.

No Comments