Jack @ ASP.NET

As a software engineer, I focus on .NET, especially asp.net, C#, WCF and so on, and I am also very interested in Search Engine Optimization.

Patch for Visual Studio 2010 RC Intellisense Crash Issue

Crash Symptom

If you are encountering frequent VS 2010 crashes when you are typing in the editor while Intellisense is popping up and/or being dismissed then you are running into this issue.

Why does the crash happen?

The most common cause of the crash happening is that you are running a machine that:

  • Is a Tablet PC (even if you aren’t using the pen)
  • Has multi-touch screen drivers enabled
  • Has an external input device like a pen or Wacom tablet
  • Has a screen-reader enabled

It turns out that a late fix right before the RC shipped modified a UI input code path that unfortunately exposed this bug.

Patch Now Available

Please apply it if you are encountering any crashes with the VS 2010 RC, or if you have a tablet, multi-touch, screen-reader or external devices attached (including Wacom tablets, phones/ipods, and others that connect via USB).

Download: http://connect.microsoft.com/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=26662

  • Digg
  • DZone
  • Yahoo Buzz
  • Delicious
  • Reddit
  • StumbleUpon
  • SmakNews
  • Jumptags
  • Ping
  • Share/Bookmark

ASP.NET MVC 2 RC2 (Release Candidate 2) Released

ASP.NET MVC 2 is a framework for developing highly testable and maintainable Web applications by leveraging the Model-View-Controller (MVC) pattern. The framework encourages developers to maintain a clear separation of concerns among the responsibilities of the application – the UI logic using the view, user-input handling using the controller, and the domain logic using the model. ASP.NET MVC applications are easily testable using techniques such as test-driven development (TDD).
The installation package includes templates and tools for Visual Studio 2008 SP 1 to increase productivity when writing ASP.NET MVC applications. For example, the Add View dialog box takes advantage of customizable code generation (T4) templates to generate a view based on a model object. The default project template allows the developer to automatically hook up a unit-test project that is associated with the ASP.NET MVC application.
Because the ASP.NET MVC framework is built on ASP.NET 3.5 SP 1, developers can take advantage of existing ASP.NET features like authentication and authorization, profile settings, localization, and so on. Download it at: http://www.microsoft.com/downloads/details.aspx?FamilyID=7aba081a-19b9-44c4-a247-3882c8f749e3&displaylang=en

What is new:

  • The new ASP.NET MVC 2 validation feature now performs model-validation instead of input-validation (this means that when you use model binding all model properties are validated instead of just validations on changed values of a model).  This behavior change was based on extensive feedback from the community.
  • The new strongly-typed HTML input helpers now support lambda expressions which reference array or collection indexes.  This means you can now write code like Html.EditorFor(m=>m.Orders[i]) and have it correctly output an HTML <input> element whose “name” attribute contains the index (e.g. Orders[0] for the first element), and whose “value” contains the appropriate value.
  • The new templated Html.EditorFor() and Html.DisplayFor() helper methods now auto-scaffold simple properties (and do not render complex sub-properties by default).  This makes it easier to generate automatic scaffolded forms.  I’ll be covering this support in a future blog post.
  • The “id” attribute of client-script validation message elements is now cleaner.  With RC1 they had a form0_ prefix.  Now the id value is simply the input form element name postfixed with a validationMessage string (e.g. unitPrice_validationMessage).
  • The Html.ValidationSummary() helper method now takes an optional boolean parameter which enables you to control whether only model-level validation messages are rendered by it, or whether property level validation messages are rendered as well.  This provides you with more UI customization options for how validation messages are displayed within your UI.
  • The AccountController class created with the default ASP.NET MVC Web Application project template is cleaner.
  • Visual Studio now includes scaffolding support for Delete action methods within Controllers, as well as Delete views (I always found it odd that the default T4 templates didn’t support this before).
  • jQuery 1.4.1 is now included by default with new ASP.NET MVC 2 projects, along with a –vsdoc file that provides Visual Studio documentation intellisense for it.
  • The RC2 release has some significant performance tuning improvements (for example: the lambda based strongly-typed HTML helpers are now much faster).
  • Digg
  • DZone
  • Yahoo Buzz
  • Delicious
  • Reddit
  • StumbleUpon
  • SmakNews
  • Jumptags
  • Ping
  • Share/Bookmark

C# Code Snippet: Finding a Node in an XML String

XML to be operated on:

   1: <States>

   2:   <State name="Wisconsin">

   3:     <Regions>

   4:       <Region name="Milwaukee">

   5:         <Area name="Mukwanago"/>

   6:         <Area name="Germantown"/>

   7:       </Region>

   8:       <Region name="Fox Valley">

   9:         <Area name="Oshkosh" />

  10:         <Area name="Appleton" />

  11:       </Region>    

  12:     </Regions>

  13:   </State>

  14: </States>

C# code:

   1: // using System.Xml.Linq

   2:  

   3: // make sure the xml file exists

   4: XElement states  = XElement.Load("testXML.xml");

   5:  

   6: // Using LINQ

   7: XElement foundNode;

   8: var query = from XElement r in states.Descendants("Region")

   9:                    where r.Attribute("name").Value == "Milwaukee"

  10:                    select r;

  11: foundNode = query.FirstOrDefault();

  12:  

  13: // Using Lambda expressions

  14: foundNode = states.Descendants("Region").

  15:      Where(r => r.Attribute("name").Value ==

  16:                          "Milwaukee").FirstOrDefault(); 

  • Digg
  • DZone
  • Yahoo Buzz
  • Delicious
  • Reddit
  • StumbleUpon
  • SmakNews
  • Jumptags
  • Ping
  • Share/Bookmark

How to manually remove programs from the Add or Remove Programs tool

The Currently installed programs list in the Add or Remove Programs tool lists all of the Windows-compatible programs that have an uninstall program or feature. Occasionally, a program may not be removed completely, and the registry key that is used to display the program in the Currently installed programs list remains. In this situation, you may need to manually remove the program from the Currently installed programs list in Add or Remove Programs. To do this, follow these steps.image

  1. Click Start, and then click Run.
  2. In the Open box, type regedt32, and then click OK.
  3. In Registry Editor, locate the following registry key:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall

  4. In the left pane, click the Uninstall registry key, and then click Export on the File menu.
  5. In the Export Registry File dialog box that appears, click Desktop in the Save in list, type uninstall in the File name box, and then click Save.
  6. Each key listed under Uninstall in the left pane of Registry Editor represents a program that is displayed in the Currently installed programs list of the Add or Remove Programs tool. To determine which program that each key represents, click the key, and then view the following values in the details pane on the right:

    DisplayName: The value data for the DisplayName key is the name that is listed in Add or Remove Programs.
    -and-
    UninstallString: The value data for the UninstallString key is the program that is used to uninstall the program.

  7. After you identify the registry key that represents the program that you removed but which is still displayed in the Currently installed programs list of Add or Remove Programs, right-click the key in the left pane of the Registry Editor window, and then click Delete.
    Click Yes in response to the "Are you sure you want to delete this key and all of its subkeys?" message.
  8. On the File menu, click Exit to quit Registry Editor.
  9. Click Start, click Control Panel, and then click Add or Remove Programs.
    In the Currently installed programs list, verify that the program whose registry key you deleted is no longer listed.
  10. Do one of the following:
    • If the program list is not correct in Add or Remove Programs, double-click the Uninstall.reg file that you saved to your desktop in step 5 to restore the original list of programs in the registry.
      -or-
    • If the program list is correct in Add or Remove Programs, right-click the Uninstall.reg file on your desktop, and then click Delete.
  • Digg
  • DZone
  • Yahoo Buzz
  • Delicious
  • Reddit
  • StumbleUpon
  • SmakNews
  • Jumptags
  • Ping
  • Share/Bookmark

TODO Comments in Visual Studio

Using TODO

imageTODO comments allow you to tell Visual Studio to maintain a central list of tasks, which it reads from many different places in your code. The Task List is a panel or floating window in Visual Studio that will display all the TODO comments in your project. To open the list, go to View menu -> Task List.

Some example TODO comments

You probably have a lot of code that needs a lot of work. If you don’t, then you need to write code that needs a lot of work. Here are some examples of TODO lines that Visual Studio 2008 will notice and put into its special Task Pane.

//todo: your task 1
//TODO: your task 2
// Todo your task 3

Description of example. This will appear in your tasks pane as a separate task. Note that you have some flexibility with these tokens. The strings "todo", "TODO", and "TODO" all work equally well—Visual Studio’s parser gives you a little bit of freedom.

  • Digg
  • DZone
  • Yahoo Buzz
  • Delicious
  • Reddit
  • StumbleUpon
  • SmakNews
  • Jumptags
  • Ping
  • Share/Bookmark

Tips and Tricks for the Visual Studio .NET IDE

1. Record and play temporary macro

Ctrl+Shift+R to record a new temporary macro. Press Ctrl+Shift+R to stop recording. Ctrl+Shift+P to play the recorded macro.

This works similar to *recording* in Vim. If you think you are going to be repeating a set of keyboard keys, then record them once and play them each time after.

2. Multiple copy/pastes

Ctrl+Shift+V cycles through the clipboard ring. You can copy/cut multiple times from one area of code, then go to another area and paste them one after another.

3. Drag and drop code snippets

The Toolbox (Ctrl+Alt+X) window has multiple tabs. You can drag and drop code onto this window and copy it elsewhere. Some tabs do not allow dropping code into them; those that allow will have the appropriate icon. The General tab works for me.

4. Previous cursor positions

Ctrl+- i.e. Ctrl + Hyphen. This cycles you through the code positions you visited.

Ctrl+Shift+- to navigate in the opposite direction.

5. Incremental search

To incrementally search for text as you type, first press Ctrl+i. Then type the word you want to search. Hit backspace to clear a character and enter to finish. Pressing F3 after this will work as usual, i.e. search for the next occurrence of previous search.

Ctrl+iCtrl+i works like F3.

6. Matching brace/comment/region/quote

Ctrl+] takes you to the matching brace. It also takes you to the matching comment, region or quote depending on what is at the cursor now.

7. Vertical block selection

Press Alt and then select the area you want with your mouse.

8. Closing/Showing support windows

There are a bunch of necessary/useful windows in the Visual Studio IDE like Properties (F4), Solution Explorer (Ctrl+Alt+L), Output Window (Ctrl+Alt+O), Task List (Ctrl+Alt+K) etc. However, they take up a lot of space. An easy way around this is to use the auto hide feature.

Open the window you want. Right click on its title and choose Auto Hide. The window will dock in whenever your mouse is not hovering over it.

9. Tab groups – group code editor windows

If you have many source code windows open, you can group them logically using tab groups. Right click the tab of the code window and choose New Horizontal Tab Group. This will move the window into a split window, allowing you to see both files. You can add more files to this new tab group and also move files back to the previous group by choosing Move To Previous Tab Group.

10. Track things you have to do with Task List

The Task List window (Ctrl+Alt+K) allows you to keep track of the things you have to do. Right click on the Task List window and choose Show Tasks|All to see a list of tasks. Ctrl+Shift+F12 to cycle through your list of tasks.

By default, comments marked with a TODO will appear in the task list.

11. Edit Task List Comment Tokens

You can add your own set of comment tokens (like the TODO comment token). Goto Tools|Options|Environment|Task List|Comment Tokens and make your changes. You can change the priority appearance of each comment token too.

12. Add Task List Shortcut

Add a shortcut to the task list with Ctrl+K, Ctrl+H. This will add the current line to the task list.

13. Auto-complete

Press Ctrl+Space or Alt+RightArrow to auto-complete the word. Intellisense suggestions may pop up a window if there is more than one possibility.

14. Intellisense suggestions window

Press Ctrl+Shift+Space to bring up the intellisense suggestions window. When giving parameters for functions, I often need to escape the suggestions window to check another part of code. To bring it back, I used to delete a comma and then type it again; but this is easier.

15. Word wrap

Ctrl+R Ctrl+R

or

Tools|Options|Text Editor|All Languages|General|Word Wrap

If you want to set this option for only one language, then choose the appropriate language instead of All Languages.

16. Line numbering

Tools|Options|Text Editor|All Languages|General|Line numbers.

  • Digg
  • DZone
  • Yahoo Buzz
  • Delicious
  • Reddit
  • StumbleUpon
  • SmakNews
  • Jumptags
  • Ping
  • Share/Bookmark