Thursday, January 22, 2009

Installing AJAX Control Toolkit For Visual Studio 2005

My previous blog was based on my experience with “System.Web.Extensions” dll. You would have read the bucket full of hardships I had to face. This blog is continuation of the hardship I faced in the same project when I tried adding the Ajax Control toolkit for Visual Studio (VS 2005). This time I was lucky not to face too much problem.

As the project was using ASP.NET AJAX 1.0 controls I needed to install the same controls in the toolbox of VS so that I can use them in the project, also this will help me to just drag the controls and place them on ASP.NET pages. The steps to install the AJAX control toolkit for .NET Framework 2.0, ASP.NET AJAX 1.0 and Visual Studio 2005 are

  1. Obviously the first step is to download the toolkit. So what you are waiting for, download the toolkit from here. (http://www.codeplex.com/AjaxControlToolkit/release/projectreleases.aspx?releaseid=11121)

  2. Once you have downloaded the toolkit there are two ways in which you can proceed. Unpack/Unzip the whole contents or just find and unpack/unzip “AjaxControlToolkit.dll” alone.

  3. Next, open VS 2005 and right click on the toolbox' and select “Add Tab” option from the menu and give a name.

image
  1. Right click the new group and select “Choose Items” from the menu.

image
  1. From the “Choose Toolbox Items” dialog box’s “.NET Framework Components” tab click the browse button. Navigate to the folder where you have unzipped the “AjaxControlToolkit.dll” (If you have Unpacked/Unzipped the whole content of the zip file then you can find the dll in “SampleWebSite\Bin” folder.). Select the “AjaxControlToolkit.dll” and click open.

image
  1. Once you click open from Open File dialog box, “Choose Toolbox Items” dialog will highlight all the controls embedded in the dll. Finally select the control you want to add in the toolbox and click “Ok”. By default all the new controls will be highlighted and check marking one control will check mark the whole AJAX controls. The screen shot sorted based on the AJAX controls is pasted below.

image

After checking all the controls I clicked “Ok”. What the heck another error? My date with errors is not gonna get over in this project. Oh no!!

I tried once again but all in vain. The below error kept on popping up.

“There was an error loading types from assembly 'C:\Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025\AjaxControlToolkit.dll’”

Googling was in vain. Different combination of searches with different keywords didn't help either. I don't know what went in my mind, I opened another instance of VS 2005 and created a dummy web application and tried adding the AJAX Control’s dll and voila the controls got added. How weird, I was thinking? Oh Microsoft, I have heard people saying many weird things happen with Microsoft softwares, here I am facing one such thing. :) Anyway my prob was solved.

I went to the previously opened instance of VS to check whether the newly added toolbox had any impact. No, obviously there will be no impact, so to try my luck once again I followed the above steps to add the controls. But again the same error. What *#*#*$*&*##? Ok, let me close the current instance of VS and open a new instance and try it. I did the same, closed VS and opened a new instance of VS. Just to make sure that the project in which I am working is not the culprit I opened the project. On inspecting the toolbox there you have it, the “AjaxControlToolkit”. Wow at last everything is falling in place. After this incidence I concluded, in future, if I have some problem like this I will follow either of the steps listed below. I would request others also to do the same. Who knows when the system behaves so weirdly? Any one of the below step may solve your problem.

  • Try adding items to the current instance of VS, if that doesn't help then

  • Open a new instance of the software and try installing the items, if that also doesn't help then

  • Restart the system and try installing the items, if that also doesn't help then

  • Try reinstalling the software (VS) and then try once again, if that also doesn’t help then god bless you. :)

The last step of reinstalling VS was suggested by many in various forums and they have confirmed that reinstalling has solved their problem. Anyway one of the above steps should solve your problem.

Know more,

Sandeep

Thursday, January 8, 2009

My Experience with System.Web.Extensions.

Recently I had to work on a project developed on .NET 2.0 and this blog is on my experience with “System.Web.Extensions” dll. So after getting a brief introduction from one of my colleagues on what is the project is all about, I Checked out the project from the source safe and was eager to compile the project and see the output in my machine. Every damn developer' wish. All developers will agree with me on this, whatever you see or know about the project one gets a totally different feeling on seeing the code running successfully in his/her machine. Ok leave that and coming back to the point. After checking out the code I pressed F5 and here comes my first problem. The error which I got is pasted below.

“Could not load file or assembly 'System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified”

Ok, the file may not be there I thought, but, where to find this file? I searched the web for answers but it was in vain. So I thought why not search for the file “System.Web.Extensions” in my system. So in search criteria I gave something like this “*Extensions.dll”. One of the files from the search result was “System.Web.Extensions.dll” in “Program Files\Reference Assemblies\Microsoft\Framework\v3.5” folder. So with this information I could figure out what is the actual problem. I have asked for a system with Visual Studio 2005 and .NET 2.0 pre-installed but the infra team gave me more than what I asked for. They installed VS 2005 and .NET 3.5. As the project was developed in .NET 2.0 it was searching for “System.Web.Extensions” dll of .NET 2.0 version, which unfortunately was not there in my system. The reason why there is no version of .NET 2.0 version of “System.Web.Extensions” is that .NET 3.5 comes with its own version of “System.Web.Extension” file versioned “3.5.30729.1”.

But how could the system look for version “1.0.61025.0” version of the dll? Then finally I got reminded that with .NET 2.0 most of the dll references are automatically embedded in the web.config file. On inspecting the web.config file I could see an entry as shown below. 

<add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>

So in the web.config the “System.Web.Extensions” dll referenced was that of .NET 2.0 and whereas the one available in my system belonged to the 3.5 version of .net. After doing some googling I came to know that there should be a “System.Web.Extensions” dll for the .NET 2.0 version ideally located at the “Program Files\Microsoft ASP.NET\ASP.NET 2.0 AJAX Extensions\v1.0.61025”. When searched, there was no folder named “Microsoft ASP.NET” under the “program files” folder in my machine. So I narrowed down the problem that there is no dll for .NET 2.0. One thing which I would like to point out is the discrepancies in the folder structure. For AJAX controls targeting .NET 2.0 Microsoft adds a folder called “Microsoft ASP.NET” and dumps all the files whereas for .NET 3.5 they create new folders. Atleast the folder structure could have been kept same.

One of the advantages of .Net which we learned in our early days of .NET is that you can have multiple version of the same dll in the same machine. Keeping this in mind I thought I will try installing the “System.Web.Extensions.dll” for .NET 2.0. Downloaded the dll from the link here and installed the same. Once the installation was over the necessary files and folders were created under “Program Files” folder which was missing earlier.

Happy to solve this problem I hit the F5 button to see the output, bloody developers eagerness. I paid for my eagerness, here comes the next error.

“There is no web named "/XXX". If this Web site exists on the server, check to make sure the FrontPage Server Extensions are installed, and that you have permission to access the server.”

What on earth is happening? I had no other go other than solving the problem. As the error says there is no web site by the name, “XXX”, the best place to search for it was in IIS. Opened IIS and started searching for the website. What the heck, the website is available and why the hell VS is throwing this error. Is it gone mad or what? Ok let’s see the properties. Right clicked and saw the properties.

image

As you can see from the above screenshot, the Application Name textbox was empty. So I removed the application by clicking the Remove button and clicked Create button (Once you click the Remove button, it changes to Create).

image

Once you click the Create button the application textbox is filled with virtual directory name, in this case the name will be XXX.

image

After doing the above changes here comes the next problem. :(

“The type 'System.Web.UI.ScriptManager' exists in both
'c:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions
\3.5.0.0__31bf3856ad364e35\System.Web.Extensions.dll' and 'c:\WINDOWS\assembly\GAC_MSIL\System.Web.Extensions
\1.0.61025.0__31bf3856ad364e35\System.Web.Extensions.dll'”

No not again I cried. I have installed the “Extensions” dll for .NET 2.0 because of that the Global Assembly Cache (GAC) has two versions of the same dll and now the system is confused as to which dll to load. This is something new, but I knew the solution. I need to remove one of the dlls from the GAC. Now how to do that? This didn't turn out to be hard. I need to just type the following command in the run (Start Menu—>Run…) window of windows.

%systemdrive%\Windows\Assembly

This popped up the below window.

image

I tried clicking the delete button on the toolbar but here comes the next message.

image

Oh my god this is too, three and four much. Another Error! Till now the system was confused on which dll to load and with this error I was confused on what the hell is happening. Is there any end to my hardships? Till now searching in the web for the various problems I faced didn't give any results so I was thinking whether I will find any solution for this problem. But luckily some googling helped me to solve the above problem. The solution was very simple and weird. I had to copy the two dlls i.e. “System.Web.Extensions” and “System.Web.Extendions.Design.dll” to the bin folder of my website. This is to tell the framework that if there is more than one version of the same dll then load the one which is there in the bin folder. To test my solution I clicked F5 and there you have it, my website is up and running without any further hiccup. Wow, at last my probs have been sorted out. But I was little bit skeptical because of the various problems I faced one after the other. So to be on the comfortable side I started testing one or two pages in the website just to make sure I don't face any further problems. Luckily my tryst with errors was finally over and I didn’t face further problems.

In the next blog we will see the hardships faced while installing Ajax Control Toolkit for .NET 2.0.

Know More.

Sandeep