Sep 22, 2011

Telerik Design-time Troubleshooting

Source: Telerik API Documentation


Starting from Q1 2009 (Version 2009.1.311) there is a brand new assembly installed in your GAC - Telerik.Web.Design.dll. We decided to separate the design-time code from the web control implementation code. The reasons are many - better separation of concerns, less assembly references for the main assembly (Telerik.Web.UI.dll). We now have the freedom to extend the design time capabilities of RadControls for ASP.NET Ajax without bloating the main control assembly.


Why didn't we make it that way from the beginning? The only reason is that Visual Studio 2008 had a problem with loading GAC-ed design-time assemblies of control libraries deployed in the BIN folder of a web site. Strangely enough the problem didn't appear in Visual Studio 2005. The good news is that this bug has been fixed in Visual Studio 2008 SP1! The problem does not exist in Visual Studio 2010 RC as well.


If you for some reason cannot upgrade to Visual Studio 2008 SP1 you might face the following exception after upgrading to RadControls for ASP.NET Ajax Q1 2009 or later:
Error Creating Control - RadControl
Failed to create designer ...
Below is a screenshot of two ways this error gets represented to the end user:


Important: The instructions below are not applicable if you used the RadControls for ASP.NET AJAX installer to setup RadControls on your machine and you have Visual Studio 2005 and/or Visual Studio 2008 SP1 and/or Visual Studio 2010. The design time should work properly out of the box with that setup.
Note
The Telerik.Web.Design assembly contains the Visual Studio designers of the controls. You don't need to add a reference to it into your project.
There are three ways to solve this problem (apart from the obvious upgrade to Visual Studio 2008 SP1):
  1. Bin-deploy the design-time assembly
    This solution would work only in case you have not installed RadControls for ASP.NET Ajax using the provided setup program. Assemblies installed by a setup program cannot be removed from GAC until the program is uninstalled. This approach is suitable when using only the dll-s from a zip (be that a hotfix or latest internal build).
    • Remove Telerik.Web.Design.dll from the GAC (this would fail if you have installed RadCotnrols for ASP.NET Ajax via the installer)
    • Copy Telerik.Web.Design.dll to your project's BIN subfolder. Ensure that the version of the Telerik.Web.Design assembly is the same as the version of the Telerik.Web.UI assembly. Don't add a reference to the Telerik.Web.Design assembly, perform a simple Windows Explorer-copy.
    • Restart Visual Studio
    Note
    The Visual Studio Extensions for RadControls for ASP.NET AJAX help handle this approach.
  2. GAC-deploy the control library assembly
    • Add Telerik.Web.UI.dll in the GAC (see details in this topic)
    • Remove Telerik.Web.UI.dll from your bin folder
    • Make sure you have the following line in your web.config:
      Copyweb.config
      <add assembly="Telerik.Web.UI, Version=2009.1.311.35, Culture=neutral, PublicKeyToken=121FAE78165BA3D4"/>

    • Restart Visual Studio

  3. Copy Telerik.Web.UI.dll to c:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PublicAssemblies and restart Visual Studio.
    Note
    Using the third approach (copying the Telerik.Web.UI assembly to the [VisualStudioInstallationFolder]\Common7\IDE\PublicAssemblies folder) could itself cause the problem described above. If you open a project, using a different version of the Telerik.Web.UI assembly than the one in the PublicAssemblies folder, the IDE could display an InvalidCast error message. It is suggested that you ensure the version of the Telerik.Web.UI assembly used by your project and its version in the PublicAssembliesfolder are the same before loading the IDE.
    This instance of the error usually happens when upgrading RadControls for ASP.NET AJAX.
Collapse imageUnknown server tag/Could not load file or assembly errors


Problem: When a project using RadControls is open and a page is loaded, a page displays the “Unknown Server Tag” or "Could not load file or assembly 'Telerik.Web.UI, version='XXXXX'..." error.
Unknown server tag
Reason: This error usually happens when the project does not contain a reference to the Telerik.Web.UI assembly, or the reference is broken.Possible causes for the errors:
  • There is a GAC-reference for the Telerik.Web.UI assembly in the project and the GAC has been updated (the “old” Telerik.Web.UI assembly is deleted and a “new” one is added to the GAC). As a result, the Telerik.Web.UI assembly, referenced by the WebSite, does not exist in the GAC.
  • There is a BIN-reference for the Telerik.Web.UI assembly in the project, which has been deleted for some reason. As a result, Visual Studio cannot find the Telerik.Web.UI assembly.
  • The reference to the Telerik.Web.UI assembly (either in Register directive or web.config, or Telerik http handlers/modules registrations in web.config) contains hard-coded version number which does not match the version of the Telerik assembly referenced in your project.
Solutions:
  1. Update the reference to the Telerik.Web.UI assembly in your project

    1. GAC Reference:

      1. Manually: By editing the web.config and/or the ASPX/ASCX/Master/UserControl files to reflect the assembly version change. You can also skip to specify the exact assembly version to prevent future conflicts.

      2. Automatically: By using the Property Pages. You will still need to update the <%@ Register Assembly=”Telerik.Web.UI”… %> directives in your pages manually.
        Property pages
        Telerik.Web.UI project reference
        Note: To avoid the need to manually modify the <%@ Register Assembly=”Telerik.Web.UI”… %> directives, we recommend that you register the tagprefix in the web.config instead, as shown in the screenshot below
        Telerik TagPrefix registration

  2. Bin reference:

    1. Browse to the Telerik.Web.UI assembly through the Property Pages
      Browser to reference
      Note: When browsing to the Telerik.Web.UI assembly in the context of a WebSite Project, Visual Studio will always add a GAC reference if it finds the same version of the Telerik.Web.UI assembly.

    2. Use the Convert To Telerik project menu item available under the Telerik -> RadControls for ASP.NET AJAX menu in Visual Studio*.
      *Available when the Visual Studio Extensions feature has been selected during RadControls for ASP.NET AJAX install.
Collapse imageAn unhandled exception has occurred. [A][control type] cannot be cast to [B][control type]
Error Message: Design time displays error rendering control (Error: "An unhandled exception has occurred. [A][control type] cannot be cast to [B][control type]. Type A originates from 'Telerik.Web.UI, Version=[Version], Culture=neutral, PublicKeyToken=121fae78165ba3d4' in the context 'LoadNeither' at location '[location1]'. Type B originates from 'Telerik.Web.UI, Version=[Version], Culture=neutral, PublicKeyToken=121fae78165ba3d4' in the context 'LoadNeither' at location '[location2]'.")
Error Rendering Control


Reasons: Using the Trial and the Dev variations of the RadControls assembly (having the same version) in a single instance of Visual Studio.
  • A typical scenario:
    1. Start Visual Studio.
    2. Open a project referencing the Trial variation of the Telerik.Web.UI assembly.
    3. Load a page with RadControls in design mode
    4. Close the project without closing Visual Studio.
    5. Open a project referencing the Dev variation of the Telerik.Web.UI assembly (versioned as the Trial one) in the same instance of Visual Studio.
    6. Load a page with RadControls in design mode
The reason for the error is that the .NET Framework cannot distinguish the Dev assembly from the Trial one. Once one assembly loaded in the Visual Studio AppDomain, it cannot be unloaded until the IDE gets closed.


Suggested solution:
Restart Visual Studio between the reload one of the two projects
Note: It is a good practice to use the Dev variation of the Telerik.Web.UI assembly in all your projects once purchased. This will ensure you avoid the design time error described above. It will also ensure you won't get undesired Trial messages when running your project.

Aug 26, 2011

Server.Transfer vs. Response.Redirect

ping from http://www.developer.com/net/asp/article.php/3299641/ServerTransfer-Vs-ResponseRedirect.htm 

If you read a lot of industry magazines and ASP.NET code samples, you may find that, although the majority use Response.Redirect to send the user to another page, some seem to prefer the rather mysterious-sounding Server.Transfer. So, what's the difference?

Well, Response.Redirect simply sends a message down to the browser, telling it to move to another page. So, you may run code like:

Response.Redirect("WebForm2.aspx")

or

Response.Redirect("http://www.karlmoore.com/")

to send the user to another page.

Server.Transfer is similar in that it sends the user to another page with a statement such asServer.Transfer("WebForm2.aspx"). However, the statement has a number of distinct advantages and disadvantages.

Firstly, transferring to another page using Server.Transfer conserves server resources. Instead of telling the browser to redirect, it simply changes the "focus" on the Web server and transfers the request. This means you don't get quite as many HTTP requests coming through, which therefore eases the pressure on your Web server and makes your applications run faster.

But watch out: because the "transfer" process can work on only those sites running on the server, you can't use Server.Transfer to send the user to an external site. Only Response.Redirect can do that.

Secondly, Server.Transfer maintains the original URL in the browser. This can really help streamline data entry techniques, although it may make for confusion when debugging.

That's not all: The Server.Transfer method also has a second parameter—"preserveForm". If you set this to True, using a statement such as Server.Transfer("WebForm2.aspx", True), the existing query string and any form variables will still be available to the page you are transferring to.

For example, if your WebForm1.aspx has a TextBox control called TextBox1 and you transferred to WebForm2.aspx with the preserveForm parameter set to True, you'd be able to retrieve the value of the original page TextBox control by referencing Request.Form("TextBox1").

This technique is great for wizard-style input forms split over multiple pages. But there's another thing you'll want to watch out for when using the preserveForm parameter. ASP.NET has a bug whereby, in certain situations, an error will occur when attempting to transfer the form and query string values. You'll find this documented at http://support.microsoft.com/default.aspx?id=kb;en-us;Q316920.

The unofficial solution is to set the enableViewStateMac property to True on the page you'll be transferring to, then set it back to False. This records that you want a definitive False value for this property and resolves the bug.

So, in brief: Response.Redirect simply tells the browser to visit another page. Server.Transfer helps reduce server requests, keeps the URL the same and, with a little bug-bashing, allows you to transfer the query string and form variables.

Top Tip: Don't confuse Server.Transfer with Server.Execute, which executes the page and returns the results. It was useful in the past, but, with ASP.NET, it's been replaced with fresher methods of development. Ignore it.

About the Author

Karl Moore (MCSD, MVP) is an experience author living in Yorkshire, England. He is author of numerous technology books, including the new Ultimate VB .NET and ASP.NET Code Book, plus regularly features at industry conferences and on BBC radio. Moore also runs his own creative consultancy, White Cliff Computing Ltd. Visit his official Web site at www.karlmoore.com.

Improve Team Foundation System Compare/Merge function

We (.NET developer) probably agrees that the built-in compare/merge tool of TFS is not good enough.

OK I know we have better solutions to do code compare/merge  (for e.g: WinMerge, Beyond Compare…etc).
Good news: we can use these software as custom tools in TFS.

2011-08-26_142024

Step 1: In Visual Studio, click Tools –> Options

Step 2: Go to Source Control –> Visual Studio Team Foundation Server

Step 3: Click Configure User Tools,

Step 4: Click Add/Remove/Modify to setup your custom tools. Configure the path and arguments as you want.

Enjoy ! Happy code comparing

Aug 23, 2011

Tidy up a messy XML

Notepad++ ( download here) can help a lot in re-format or tidy up an messy XML

From Notepad++ menu: TextFX -> HTML Tidy -> Tidy: Reindent XML

This feature however wraps XMLs and that makes it look 'unclean'. To have no wrap,

  • open C:\Program Files\Notepad++\plugins\Config\tidy\TIDYCFG.INI,
  • find the entry [Tidy: Reindent XML] and add wrap:0 so that it looks like this:
[Tidy: Reindent XML] 
input-xml: yes
indent:yes
wrap:0
Enjoy XML everyone !

Aug 21, 2011

Dynamic calculation of field values in TFS 2010

If you are here because you might want to ask TFS 2010 to auto-update some fields (such as remaining work vs. completed work), then you’re lucky because of there is a TFS Aggregator plugin:

http://tfsaggregator.codeplex.com/

Download link : here 

This server-side plugin let TFS does such things. Some of its nice features:

  • Update the state of a Bug, PBI (or any parent) to "In Progress" when a child gets moved to "In Progress"
  • Update the state of a Bug, PBI (or any parent) to "Done" when all children get moved to "Done" or "Removed"
  • Update the "Work Remaining" on a Bug, PBI, etc with the sum of all the Task's "Work Remaining".
  • Update the "Work Remaining" on a Sprint with the sum of all the "Work Remaining" of its grandchildren (i.e. tasks of the PBIs and Bugs in the Sprint).
  • Sum up totals on a single work item (ie Dev Estimate + Test Estimate = Total Estimate)

OK that’s it. Please visit the site for more info.

Happily working on Sunday.