InvalidOperationException

Discussions related to custom development with Select.
Post Reply
dutil
Posts: 33
Joined: Thu Dec 19, 2019 12:10 pm

InvalidOperationException

Post by dutil »

Hello,

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.

Code: Select all

System.InvalidOperationException: Failed to add item.
   at SoftPro.ClientModel.Proxies.FaultTolerantClientChannel`1.HandleFaultException(FaultException exception)
   at SoftPro.ClientModel.Proxies.FaultTolerantClientChannel`1.InvokeCall(String action, Object[] args)
   at SoftPro.OrderTracking.Client.Orders.OrderStoreServiceClient.OpenOrder(OrderIdentifier id, OrderEditMode mode, Boolean exclusiveLock)
   at SoftPro.OrderTracking.Client.Orders.OrderStore.OpenOrder(OrderIdentifier id, OrderEditMode mode, Boolean exclusiveLock)
   at SoftPro.OrderTracking.Client.Orders.OrderStore.SoftPro.OrderTracking.Client.Orders.IOrderStore.OpenOrder(IOrderInfo orderInfo, OrderEditMode mode, Boolean exclusiveLock)
   at SoftPro.OrderTracking.Client.Orders.OrderStore.SoftPro.OrderTracking.Client.Orders.IOrderStore.OpenOrder(IOrderInfo orderInfo, OrderEditMode mode)
and

Code: Select all

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)
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: InvalidOperationException

Post by BobRichards »

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?
Bob Richards, Senior Software Developer, SoftPro
dutil
Posts: 33
Joined: Thu Dec 19, 2019 12:10 pm

Re: InvalidOperationException

Post by dutil »

The "Operation is not valid due to the current state of the object." occurs when we call ApplyChanges on an order.

Code: Select all

_orderStore.ApplyChanges(order);
The "Failed to add item." occurs when we try to open an order. Usually, this one occurs after the aforementioned one.

Code: Select all

var order = _orderStore.OpenOrder(search, OrderEditMode.ReadWrite);
This is C# code.
dutil
Posts: 33
Joined: Thu Dec 19, 2019 12:10 pm

Re: InvalidOperationException

Post by dutil »

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.
dutil
Posts: 33
Joined: Thu Dec 19, 2019 12:10 pm

Re: InvalidOperationException

Post by dutil »

On an order where it's happening, we just got the error message through the Select UI. Screenshot attached.
Attachments
Capture.PNG
Capture.PNG (4.72 KiB) Viewed 1728 times
BobRichards
Posts: 1376
Joined: Wed Jan 15, 2014 3:50 pm
Location: Raleigh, NC
Contact:

Re: InvalidOperationException

Post by BobRichards »

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.
Bob Richards, Senior Software Developer, SoftPro
Post Reply