Monday, September 10, 2007

Beware of String.IsNullOrEmpty

A very useful method when used with caution. Yes with caution!

Recently I was asked by our BA to use the IsNullOrEmpty method while checking for the existence of value in a string variable. Its new to me. He said that it has more performance than the usual way of doing this.

I decided to dig more about this. In the next 15 minutes i found that it has its own issues.

Yes issue, a very big one !

When used inside a loop it will crash the whole application. No error handling works here.
This is caused by JIT optimization.

Bill has a good write up about this here: http://msmvps.com/blogs/bill/archive/2006/04/04/89234.aspx

Note this happens only when you build your application in release mode with optimizations on.


Microsoft has the following page on the issue. Fix is available only in Orcas.
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=113102

Well, as for me I am now fixing those IsNullOrEmpty method calls along with the rest of the team .....

One more issue to fix ................................................... ;-)

Hello World !!!

Yes .... this is my hello world in the BLog world.....


Just like starting to learn one more language...... ;-)



Saravanan Kanagaraj