Replaced null reference exception with more meaningful to be able to find out what is wrong.