Thursday, January 31, 2013

JSON Parsers in .Net 3.5

In .Net 3.5, there are 2 built in classes to support JSON serialization and deserialization.

  • System.Runtime.Serialization.Json.DataContractJsonSerializer, in System.ServiceModel.Web.dll
  • System.Web.Script.Serialization.JavaScriptSerializerm in System.Web.Extensions.dll

Sunday, January 20, 2013

Exception: Unable to cast object of type 'System.DBNull' to type 'System.String'.

Exception: When you try to convert a DBNull value to string this error will occur.


Description: DBNull is not equivalent to null. As DBNull is a different type. So it can not be converted to string.


Fix: ADO.NET mostly returns DBNull for database null value.


ToString() on DBNull value will return empty string

Convert.IsDBNull will return true if the given value is null




String s = dr[“column”] ; // will throw error

String s= dr[“column”].ToString()l //will save empty string instead of null

String s= Convert.IsDBNull(dr[“column”])?null:dr[“column”]; // will save null for DBNull value

Wednesday, January 09, 2013

AndAlso & OrElse Operator

In VB.Net, there are two useful operators AndAlso & OrElse to Replace And & Or operators.

AndAlso & OrElse, operators are works as follows.

Both takes two operators.

When First one evaluated as false, AndAlso will not evaluate the second, as the result will surely result in false.

When First one evaluated as true, OrAlso will not evaluate the second, as the result will surely result in true.


This operation helps in one important situation, to check null and evaluate.

obj IsNot null AndAlso obj.Value=”value”

When obj is null, second condition will not be evaluated, and so, it will result in NullReferenceException.

Also, AndAlso and OrElse operators perform well than And and Or operators as the second operant will not be executed based on the result of first operand

??- Is Null Operator in C#

?? works as a Is Null operator in C#.

It can be used as

c = a??b


If a is non null value, a will be assigned to c, other wise b will be assigned to c.


?? operator is introduces in C# 2.0

Tuesday, January 08, 2013

Where is .Net 4.5 in C:\Windows\Microsoft.Net\Framework

Microsoft .Net Framework 4.5 is a replacement for Microsoft .Net Framework 4.0. It will overwrite the dlls in Microsoft .Net Framework 4.0. So it will use the following folder for its installation.