Unsafe cast on SPItemEventDataCollection.Item
Description
While using SPItemEventProperties the SPItemEventDataCollection.Item contains data for specified key. In case of key missing it returns null so null reference exceptions might be arised with ToString() call.
The following code is unsafe:
properties.AfterProperties["Contracts"].ToString();
properties.BeforeProperties["Contracts"].ToString();
Resolution
First check the result of SPItemEventDataCollection.Item access for null. Then cast it to required type.