Complete port to .Net 4.0

Complete port to .net 4.0 with similar test result of .net 3.5