An interesting customer question came my way about how to set a string to null in the Watch Window in Visual Studio .NET 2003. Note: this issue does not reproduce in Visual Studio 2005. If you try to set a string to null in the Watch Window, Visual Studio will just ignore you and will reset the value back to the original. If you try to be more forceful and use the Quick Watch window, you’ll get an error saying, “The value of this variable could not be changed. Incorrect function.”
Thanks to Ben on the C# team for the workaround:
- Add the string (for example, named "str") to the watch window
- Change the Name (in the "Name" column) to (object)str to cast it into an object
- Click the + sign to expand the entry in the watch window
- In the row that has Name "string", set the value to null
- Now you can set the Name back to str if you want to