Critical fix: InvalidCastException due to OnExit during async not handled correctly