So you are implementing a custom BizTalk tracking solution using the BAM APIs. In this solution you need to track when the message arrives at the receive port exactly and even before the receive pipeline starts to execute. so simple right you just end up doing something like this.

image

BUT BAM (not the BizTalk BAM but something blowing up) a NullReferenceException is thrown. Strange!!! and also the strangest part is that you will find that on some environments it works and on others it throws this exception.

Well the  issue here is related to the tracking setting for the receive port. If you enable tracking of message bodies on the receive port somehow this property is removed from the message context.

image