A developer registers a pre-image named PreImage on a PostOperation Update step of the contact table and selects the emailaddress1 column. At runtime the code calls context.PreEntityImages["Before"] and throws a KeyNotFoundException even though the step fires correctly. What is the most likely cause?
Select an answer to reveal the explanation.
Short Explanation
Images are handed over in a labeled box, and your code has to ask for the exact label on the box. You registered it as PreImage but you're asking for Before, so you get nothing. The trap is blaming the stage; pre-images work fine in PostOperation.
Full Explanation
When an image is registered on a step, it is placed in the PreEntityImages or PostEntityImages collection using the entity alias defined at registration. The plug-in must use exactly that alias as the key. Here the step registers the alias PreImage while the code looks up Before, so the collection has no entry under that key and the access throws even though the step itself executes. The fix is to align the alias in code with the registration, or to check with Contains before reading. Pre-images are supported on PostOperation steps; they are available on Update and Delete in PreOperation and PostOperation, so the stage is not the cause. Dataverse does not omit a registered pre-image because a column was absent from Target; the image is retrieved from the stored row regardless of which columns the update carried, although a column whose stored value is null will be missing from the image's attributes. The claim that pre-images are limited to asynchronous steps is false; synchronous and asynchronous steps both receive the images registered on them. Exam caveat: a registered image whose column list omits a column the code needs produces a similar KeyNotFoundException on the attribute rather than on the image. Operational check: compare the alias in the Plug-in Registration Tool with the string in code and trace the collection's keys.