I'm seeking assistance regarding a pricing calculation plugin in the Dynamics 365 Sales application. I've disabled the automatic system price calculation and registered the plugin following the instructions on the Microsoft page: https://learn.microsoft.com/en-us/dynamics365/sales/developer/sample-calculate-price-plugin.
For testing purposes, I've registered the plugin for both opportunities and opportunity products, as outlined in the documentation, specifically on the CalculatePrice message, Post-operation event stage, and Synchronous execution mode. The plugin aligns with the provided documentation and successfully functions when updating fields of existing products or their prices.
However, when attempting to add a new opportunity product or opportunity, I encounter the following error: /An unexpected error occurred from ISV code. In the plugin trace log, I receive the message: 'Object reference not set to an instance of an object,' with ErrorCode: 0x80040224./
When I changed the execution mode to Asynchronous, the plugin worked, and the error disappeared. However, this is not an optimal solution as it doesn't provide accurate data in a timely manner.
How can I resolve this issue? Do I need to make any changes in the code or during the plugin registration process? Any assistance would be greatly appreciated.
Thank you in advance.