Oct 28, 2011

Fix IIS error System.ServiceModel.Activation.HttpModule

 

If you hit this error, probably you are install .NET 4.0 after you installed IIS:

Could not load type ‘System.ServiceModel.Activation.HttpModule’ from assembly ‘System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′.


Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.


Exception Details: System.TypeLoadException: Could not load type ‘System.ServiceModel.Activation.HttpModule’ from assembly ‘System.ServiceModel, Version=3.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089′.

Solution:

Just run this command from Visual Studio Command Prompt:

aspnet_regiis.exe /i

The aspnet_regiis.exe is in

  • %windir%\Microsoft.NET\Framework\v4.0.30319
  • %windir%\Microsoft.NET\Framework64\v4.0.30319 (on a 64-bit machine)

Sep 24, 2011

ASP.NET disable a button during postback

http://encosia.com/disable-a-button-control-during-postback/

Postback Ritalin has been getting a lot of search hits intended to find a button disable technique for full .NET postbacks. So, this example is for all of you searching for a non-AJAX solution.

The trick is to use the OnClientClick and UseSubmitBehavior properties of the button control. There are other methods, involving code on the server side to add attributes, but I think the simplicity of doing it this way is much more attractive:

<asp:Button runat="server" ID="BtnSubmit" 
OnClientClick="this.disabled = true; this.value = 'Submitting...';"
UseSubmitBehavior="false"
OnClick="BtnSubmit_Click"
Text="Submit Me!" />

OnClientClick allows you to add client side OnClick script. In this case, the JavaScript will disable the button element and change its text value to a progress message. When the postback completes, the newly rendered page will revert the button back its initial state without any additional work.

The one pitfall that comes with disabling a submit button on the client side is that it will cancel the browser’s submit, and thus the postback. Setting the UseSubmitBehavior property to false tells .NET to inject the necessary client script to fire the postback anyway, instead of relying on the browser’s form submission behavior. In this case, the code it injects would be:

__doPostBack('BtnSubmit','')

This is added to the end of our OnClientClick code, giving us this rendered HTML:

<input type="button" name="BtnSubmit" 
onclick="this.disabled = true; this.value = 'Submitting...';__doPostBack('BtnSubmit','')"
value="Submit Me!" id="BtnSubmit" />

This gives a nice button disable effect and processing text, while the postback completes.

If you found this but are more interested in an AJAX solution to disable buttons during partial postbacks, check out either Postback Ritalin or CSS style as AJAX progress indicator.

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.

Aug 17, 2011

Favorite quotes–Quote of the day

I know this is not a technical blog – but I found it is encouraging to keep a collection of my favorite quotes and update it whenever I found a good one.

Today’s quote come from my build team:

“A true hero need not speak. The world will speak for him when he is gone”

Aug 15, 2011

Visual Studio 2005/2008: “Error Creating Control” while working with Telerik Controls

Ping back from : http://blogs.telerik.com/kevinbabcock/posts/08-12-23/visual_studio_ldquo_error_creating_control_rdquo.aspx

 
I’ve run into this error before and last night it reared its ugly head again. You’ll find it from time to time when switching to Design View in Visual Studio to work with custom server controls. The bug is in Service Pack 1 of VS and can be quite annoying.

1 - Error Creating Control Exceptions

It has been submitted to Microsoft and they claim to be working on a solution which will “fix it in subsequent releases” of Visual Studio. Unfortunately, developers (like me) don’t want their productivity to suffer while we all wait for a fix from Microsoft. So here are a couple of steps you can take to try to resolve this issue yourself:

Solution 1. Close and restart Visual Studio. Some developers claim this solved the problem for them. I cannot confirm that this works because it did not solve the problem for me, but it’s certainly worth a try since it’s quick and does not require you to modify your system in any way.

Solution 2. Delete all project assemblies from your ProjectAssemblies directory.

  • Close Visual Studio
  • Navigate to ProjectAssemblies directory
    • C:\Users\[username]\AppData\Local\Microsoft\VisualStudio\9.0\ProjectAssemblies(Windows Vista)
    • C:\Documents and Settings\[username]\Local Settings\Application Data\Microsoft\VisualStudio\9.0\ProjectAssemblies (Windows XP)
  • Remove all subdirectories
  • Restart Visual Studio

2 - ProjectAssemblies Folder

The second solution did the trick for me. Hopefully one of the above solutions worked for you. If you have run into this bug and found an alternate solution, please let me know and I’ll make sure it gets added to the list.

Aug 11, 2011

Slow connection when connecting to Team Foundation Server from Visual Studio 2010

At a client we were testing our newest line of development machines. After installing Visual Studio 2010 we noticed that the performance was VERY slow when connecting to Team Foundation Server (2010). Performing a get latest of a large solution took several hours(!).

Some investigation showed that it does not appear to be a TFS issue per se but rather something lower in the .NET Framework stack, having to do with automatic proxy discovery through the WPAD protocol.

You can work around the issue by turning off proxy autodiscovery on a per-application basis by using a .exe.config setting.

The .exe.config for Visual Studio is %VSINSTALLDIR%\Common7\IDE\devenv.exe.config and it already contains a section in the .exe.config for System.Net. After adding the defaultProxy element, that section would look like this:

 1: <system.net>
2: <defaultProxy enabled="false" />
3: <settings>
4: <ipv6 enabled="true"/>
5: </settings>
6: </system.net>

Aug 4, 2011

Render your Windows font differently – be like Mac


Have you ever feel envious with Mac OS user because of the way Mac OS renders font ?OK, I admitted I did. But no more – with the help of these things:

  • GDI++ [download]
  • Lucida Grande font [download]
  • Installation:
    - Download these 2 files above.
    - Extract the GDI++ into your Program menu folder, then put a shortcut of Gditray.exe into Startup folder
    - Extract and copy the 2 Lucida Grande fonts into C:\Windows\Fonts
    - Execute the .reg file

    Usage:
    After that, you will see GDI++ icon in the task bar. Click Use preferences –> Bold / Medium / Light.
    Click Enable

    image

    Results:

    This is what looks like with GDI enabled:image

    And GDI disabled:image

    Jul 1, 2011

    Visual Studio 2008 SP1 and Team Explorer 2008 to connect to TFS 2010

     

    If you want to use Visual Studio 2008 SP1 and Team Explorer 2008 to connect to a TFS 2010 server, you will probably hit the error while trying to add the server. It happen even when you install patch KB974558 (Team Explorer 2008 SP1 forward compatibility patch for TFS 2010)

    The Team Explorer 2008 RTM build is 9.0.21022.8. If you install Visual Studio 2008 SP1 before installing Team Explorer, then you’ll have VS 2008 SP1 with Team Explorer RTM which does not work well together.

    Figure 1 : this Team Explorer build does not work well with Visual Studio 2008 SP1 and TFS 20102011-07-01_142342_s

    So the fast solution is to run the Visual Studio 2008 SP1 again. It will look for the Team Explorer version and update to SP1. After installation complete, we should see this:

    Figure 2: Now the Team Explorer is patched to SP1 build : 9.0.30729.1, this version works with TFS 2010.

    2011-07-01_161227

    Jun 30, 2011

    How to type Vietnamese on iPhone–Làm thế nào để gõ tiếng Việt trên iPhone

     

    Steps:

    1. Go to settings –> General
    IMG_0062

    2. Go to Keyboard
    IMG_0063

    3. Go to International Keyboards
    IMG_0064

    4. Click Add New Keyboard
    IMG_0065

    5. Scroll to the end, select “Vietnamese”
    IMG_0066

    6. Review
    IMG_0067

    7. Click on the globe icon to start typing in Vietnamese
    IMG_0069

    Jun 10, 2011

    Start multiple instance of Internet Explorer with separate sessions vs. Private Mode

    IE instance with multiple sessions

    For developers who work daily with IE, we all know the pain of close all Internet Explore instance and open a new window to have a fresh new session with clean data.

    It is because of the default behavior in IE is using merged session.
    No more pain my friends. This parameter come to rescue: –nomerge

    So if you start your Internet Explore like this, you will be able to test various sessions.

    image

    What happen behind the scene:

    image

     

    For faster access, I edit the shortcut for Internet Explorer to be like:"C:\Program Files (x86)\Internet Explorer\iexplore.exe" –nomerge

    image

    Happy testing & debugging !

    Jun 2, 2011

    How to install Mac OS X Snow Leopard on VMWare 7

    I was searching all across the net to find the solution and here it is:

    http://bobhood.wordpress.com/2009/12/18/welcome-to-snow-leopard-mac-os-x-10-6-and-vmware-workstation-7/

    This tutorial also include VMware tool installation guide to improve performance. Thanks to bobhood for the excellent tutorial.

    If any of you want to customize ISO package or even just the Vmware 7 image for Snow Leopard, drop me a comment.

    Happy testing Mac OS X!

    PS: Here is another excellent tutorial:
    http://www.redmondpie.com/how-to-install-os-x-snow-leopard-in-vmware-windows-7-9140301/

    May 31, 2011

    IE slow on opening new tab

    If your IE opens a new tab slowly, probably it is because too many add-ons, or there is a heavy load add-on that delay the process.

    Solution: check your IE settings:
    -Menu > Tools > Manage add-ons : check is there any add-ons that load time is more than 0.2s, then click Disable



    Hints: 
    - A lot of toolbar add-on can slow down your IE.
    - Do not disable Java if you still need it.

    Switch back to blog-mode

    I'm swinging between blog mode vs. Facebook mode !

    Social network vs individual preferences