fixes NullReferenceException in DuplexStream