Earlier today Microsoft released the source code to the AJAX 1.0 release System.Web.Extensions library. I was in the apparently unique position of needing to modify parts of the code for a special case application, so I downloaded the source right away ready to modify, compile and deploy.
I guess I was pretty naive to think that it would be that easy. The distribution doesn’t include some pretty important parts. A .csproj file for one. The entire Resources class for another.
So I had to work my way through the process of getting a compile-able version of the library ready to replace the official System.Web.Extensions binary in my project. The server code Reference License prevents me from simply providing the project to you, but here are the high points if you need to do the same.
This is neither easy nor straightforward and I probably forgot a few steps when I was writing this. You’re gonna have to be diligent to get it to work, even with this howto.
1) Download and install the source
2) Create a new C# project in Visual Studio. You can call it whatever you want but I would suggest you avoid using the same namespace because the System.Web namespace is strongly named and exists in several assemblies. I called mine Dave.Web.Ajax
3) Copy all the files and folders from the source installed directory
(C:Program Files (x86)Microsoft ASP.NETASP.NET 2.0 AJAX Extensionsv1.0.61025SourceSystem.Web.Extensions on my computer) into your new project directory and include them in the project.
4) Make sure your Default Namespace on the project is something good – again Dave.Web.Ajax in my case.
Get the Missing Files
1) Start the .Net Reflector (if you’re a serious .Net developer, you should have downloaded this to your computer long ago, btw)
2) Open the official System.Web.Extensions.dll file
3) Save all the Resources into a new Resources folder in your project. When you save them, drop the “System.Web.Resources” part of the filename if it’s there.
4) You should now have a file called AtlasWeb.resources in your folder
5) Open a VS Command Prompt and in your resources folder run
resgen AtlasWeb.resources AtlasWeb.resx. This will generate the resx file that you need in visual studio to dynamically generate the class.
Setup your Embedded Resources
1) In VS, include all the files in the Resources in your project (except the *.resources files) if you haven’t already.
2) Select them all and set the Build Action to Embedded Resource
3) Click on the AtlasWeb.resx file and set the Custom Tool property to “ResXFileCodeGenerator”. This will generate the AtlasWeb.Designer.cs file which gives you a real class with properties for each item in the resource file.
NOTE) You might need to repeat this process (and the resgen.exe process) for the other *.resources files, but I haven’t done it and havn’t had any issues yet.
Rename the Namespace and cleanup
If you are going to stick with using the System.Web.* namespace, then you can skip this step.
1) Basically, I handled this in an iterative fashion. I did a project Find-and-Replace for “System.Web.” and replaced with “Dave.Web.Ajax.” Of course this process will break stuff because now objects that are really in the System.Web namespace (and not in the System.Web.Extensions assembly) will dissappear.
2) Get your iteration on: compile, add “using System.Web.something;” to a file with the error, compile, repeat.
Fix the Embedded Resource references
At this point, your project should compile and if you reference it in a web project in place of the System.Web.Extensions.dll file (or the GAC reference) the web project should compile too. But as soon as you load up a page with AJAX controls on it, you will get a runtime error saying the Resource File could not be found.
Update the reference names of your embedded .js files to be fully qualified. Your new fully qualified resource name will be “DefaultNamespace.Resources.Filename.js” Mine is “Dave.Web.Ajax.Resources.MicrosoftAjax.js” for example.
There are references in these files
Update those references to use the fully qualified names. After that, in WebResourceUtil.cs there is an optimization in the SystemWebExtensionsContainsWebResource(string) function that you have to modify. It does a switch statement on the length of the input string before comparing to the resource name string. Update each case conditional to be the length of the string in that case statement. If you forget this step you will be very confused why it says it can’t find a resource that you know is there…
Now, all embedded resources need an assembly reference so that they can be detected using reflection (which is how the AJAX library looks for a valid embedded resource). I just created a dummy class called Scripts.cs inside the Resources file so I could include the assembly attributes:
Assuming you’ve gotten this far, you must be dedicated or desperate. Now you can go in and make your mods to any of the AJAX files and you’re good to go. Hopefully this was helpful and I wish I could just post the project, but rules is rules.
Its been about 6 hours since I finished my conversion, so its pretty fresh in my head, but I may have forgotten a step somewhere. I’ll try to answer questions in the comments but I’m pretty busy these days and I just blew half my day because the release of AJAX doesn’t play well inside iframes (which is the whole reason I had to do this mod).
Good luck to you.
- BROWSE / IN TIMELINE
- » Sphinx Search C# .NET Client API
- BROWSE / IN dot.net
- » Sphinx Search C# .NET Client API
COMMENTS / 9 COMMENTS
SPEAK / ADD YOUR COMMENT
Comments are moderated.