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

24 comments:

  1. wow thats sucky,

    my computer tellsme when i try to ad System.Web.Extensions that it was not built agaist the silverlight runtime

    lame,

    ReplyDelete
  2. Hi Lame,

    Thats a new error. I have not worked on Silverlight, but I think this link may help you. http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/ec72ce6a-785b-4573-93e2-ec574dc38ba6/

    ReplyDelete
  3. Hi,
    your post is very helpful to me.... thanks for that....

    Prasanna ellapolu

    ReplyDelete
  4. Thanks...first full explanation I've seen.

    ReplyDelete
  5. I wish everyone post solution like this one. Not many programmers no how to write :) You are an exception though :)

    ReplyDelete
  6. Hi Anonymous,
    Thanks, I am flattered. :)

    ReplyDelete
  7. It might be I had another problem, but I got the same error. Solution was to setup AJAX for .Net 2.0 http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=ca9d90fa-e8c9-42e3-aa19-08e2c027f5d6

    ReplyDelete
  8. VERY helpful. Thanks!

    ReplyDelete
  9. Hi,
    Nice to hear that it was helpful.

    ReplyDelete
  10. I had the same error:
    “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”

    The difference is that I have my DEV web app working just last week. Then I noticed I don't have system.web.extensions.dll and system.web.extensions.design.dll in my GAC. Some other event in my desktop might have somehow removed them (not really sure what). So I got the idea of re-installing ASP.NET AJAX 1.0 from your blog post and it solved my error above.

    Thanks!
    AR

    ReplyDelete
  11. Hi AR,
    Thanks for sharing your experience. This may help others as well.

    Sandeep

    ReplyDelete
  12. Thank you man..
    this really helped me.

    ReplyDelete
  13. Happy to know that the blog helped you. Thanks guys.

    ReplyDelete
  14. Hi

    What you said the above procedure i followed, but still ajax is not working. so what culd be the raeason. please asist me.

    Thanks
    Magesh

    ReplyDelete
  15. It will more helpful if you could share the actual problem you are facing. Have tried re installing AJAX? Please provide more info...

    ReplyDelete
  16. Hey Sandeep,

    Your Blog is really cool and helped me in sorting out my issue.


    Thanks
    Sridhar

    ReplyDelete
  17. Sandeep - I'm getting another error such as "A ScriptManager is required on the page to use ASP.NET AJAX Script Components"


    [InvalidOperationException: A ScriptManager is required on the page to use ASP.NET AJAX Script Components.]
    AjaxControlToolkit.ScriptObjectBuilder.RegisterCssReferences(Control control) in C:\AjaxControlToolkit\AjaxControlToolkit\ExtenderBase\ScriptObjectBuilder.cs:305
    AjaxControlToolkit.ScriptControlBase.OnLoad(EventArgs e) in C:\AjaxControlToolkit\AjaxControlToolkit\ExtenderBase\ScriptControlBase.cs:261
    System.Web.UI.Control.LoadRecursive() +66
    System.Web.UI.Control.LoadRecursive() +191
    System.Web.UI.Control.LoadRecursive() +191
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428


    In my local system I'm using .NET3.5 version and the code on the production is .NET2.0. I have been trying to create a setup in local machine to make some changes.Reisntalled AJAX 1.0,3.5 and verified scriptmanager code also.

    It's compiling successfully but getting run time error.

    Would you please help me? Appreciate of your input and help.

    ReplyDelete
    Replies
    1. Have you used any of the ASP.NET AJAX controls? If so you need to place a ScriptManager control into your page. Drag it to your page and try running it again... Hope this helps.

      Delete
  18. Thanks for sharing your experience with us. I'll try your solution

    ReplyDelete
  19. This comment has been removed by the author.

    ReplyDelete
  20. Thank you so much. Your article was the exact solution to my problem.

    ReplyDelete
  21. Trade Stocks, Forex, And Bitcoin Anywhere In The World:tradeatf Is The Leading Provider Of Software That Allows You To Trade On Your Own Terms. Whether You Are Operating In The Forex, Stock, Or Cryptocurrency Markets, Use tradeatf Software And Anonymous Digital Wallet To Connect With The Financial World.: tradeatf Is A Currency Trading Company That Allows You To Trade Stocks, Forex, And Cryptocurrency.

    ReplyDelete

Please provide your valuable comments.