TrackActions: prefer InvalidCastException over NREs

Replace dynamic casts with static casts in a couple of places where
the null-check is not performed before dereferencing the variable.