Hello Dojo,
I'm adding a new InterApp message to a driver, the way this message needs to work is that when it's received, the driver makes an API call to the device and the message then sends a reply based on the response from the API.
The issue is that when I send this message to the driver, the driver processes the message twice. When I commented out the message.reply, the driver only processes the message once.
I store the raw message initially received in a table and use that the recreate the initial message later on when I need to reply.
Here's the code:
This is how the message is sent; I've verified that this piece of code runs only once

This is how the message is sent in the ConnectorAPI Nuget; I have also verified that this only runs once. In this case, the nevionElementId is the same as the remoteElementId. The NevionReceiverPid is 9000000 and receiverPid is 9000001
This is how the response message is made later on
Which passes the reply to this method 
WWhen the message.Reply is commented out, the message is no longer processed twice
Hi Bautista
IEnumerable<T> is lazy, meaning it doesn’t execute immediately.
The code that produces the values only runs when the sequence is enumerated.
If an IEnumerable is backed by work with side effects (like sending an InterApp message in this case) that work will run every time the sequence is enumerated. This can result in the same request being sent multiple times without it being obvious.
Since you’re seeing the request sent twice, the sequence is being enumerated twice. Common causes are calling .Any() on the collection and then iterating it again with a ForEach() for example.
Without seeing the full code, my best guess is that you first perform an .Any() check on the response collection, and if there are responses, you then iterate over them. That would explain why the request executes twice, and why it only executes once when there is no reply.
To avoid this, don’t expose side-effecting operations as a lazy IEnumerable. Instead, materialize the result before returning it (for example, using ToList() or FirstOrDefault()).
If the intent is “send once, receive all replies, then return them”:
-
Update SendRequest to return a List<Message>
-
Call .ToList() on interAppCall.Send()
If you only ever expect a single reply:
-
Update SendRequest to return a single Message
-
Call .FirstOrDefault() on interAppCall.Send()
Hope this clears things up and fixes the issue.