The screenshots speak for themselves. Debug - 4 is the most relevant shot.
Take a look at the values shown in Watch 1, and the execution path that is being followed. What should happen is, base.Text == null evaluates to true, null is returned and life is good.
What does happen, is that some how it passes over that part of the if, falls into the else and then executes the code highlighted in Debug - 4. A null reference exception is then thrown, because I try to call base.Text.Trim() when base.Text is null. Even though it should NEVER have gotten to that point.
I hope the problem is clear enough. I'm running VS2005 RTM - I've just been to busy to move over to the release version.
Screenshots are here, they appear to not be displaying correctly
http://img286.imageshack.us/img286/4056/13ct1.png
http://img145.imageshack.us/img145/9246/27qz.png
http://img182.imageshack.us/img182/3786/31uj.png
http://img145.imageshack.us/img145/8637/49al.png

Potential Bug with C#
jessj
Atilla
Thanks for the suggestion - the result was pretty unexpected. I declared the string and assigned null to it, just in case. I then assigned base.Text to it - check out the watch in the screenshot. The string I assign to is suddenly instantiated as an empty string, but base.Text is still null.
Not particularly useful, definitely but interesting :)
It's any easy enough problem to work around, but I'd love to know why it's happening. I've got a virtual pc with the VS2005 release version (rather than the RTM), so I'll move my code over to that later today and test it some more.
ND..
Phil Vaira
Maybe you could use the new tool called Deblector (a Debugger using Reflector) to step through the code: http://www.felicepollano.com/PermaLink,guid,1c863e69-1b56-4cfa-a60b-203e1127b8bd.aspx
I'd love to know what happens when you use it with the latest version.
Best of luck.
Ares01
Perhaps the string is empty (text=="") rather than null
Anyhow, with a try {...} catch {return null} you can solve the problem.
gurminder
In .NET v2.0.50727 System.Web.UI.WebControls.TextBox.Text will never return null.
I can't explain what you're seeing though when debugging with your framework version.
TaTas
Please let me know what happens then - this is really interesting :D