Looking at the msdn sample
here, I noticed that they check if
while(rdlen < totlen)
as a while condition.
You have not provided any code here, so I cannot be sure - but I guess a condition like this should be sufficient to avoid null errors? You can always directly check if an object is
null
by doing an
if
condidition check against it.