We are occasionally getting two exceptions when trying to add notes to an order through some of our custom code. We are unable to reproduce it reliably and, as a result, have been unable to find the root cause. We were hoping someone could shed some light on what causes the following exceptions to be thrown by Select. Hopefully, we can then track down what exactly it is we're doing that is causing these exceptions from Select and fix it.
System.InvalidOperationException: Operation is not valid due to the current state of the object.
at SoftPro.ClientModel.AsyncResult`1.get_Result()
at SoftPro.OrderTracking.Client.Orders.OrderStore.SoftPro.OrderTracking.Client.Orders.IOrderStore.EndApplyChanges(IAsyncResult ar)
at SoftPro.OrderTracking.Client.Orders.OrderStore.SoftPro.OrderTracking.Client.Orders.IOrderStore.ApplyChanges(IOrder order)
I'm not sure we can be of help without knowing the context around your code. Can you provide any additional information or your code when the errors occur. How often does the error occur?
The code this is from is a bit on the long side. Most of the time it works without issue and when the exceptions are thrown, the code executes just fine (our logging shows it makes it through everything). It's just on the order save and order open that we run into issues.
It sounds like you are modifying the order or adding objects before you have opened the order as writable (as ReadWrite or Design). If the order is locked or opened by someone else, modifications can't occur - or more accurately - can't be saved. I imagine that you have already looked for this scenario.
Also, if the order is already opened by a different client or user (like in an Automation Snippet), you will not be able to open the order for writing.