This project is read-only.


Message Publish within a Subscribe Error


When Publishing a new Message on the Bus within a Subscribe, a "Collection was modified; enumeration operation may not execute." error occurs.
Messages.Subscribe<Widget1>(w =>
    Messages.Publish(new Widget2());
Closed Mar 26, 2011 at 1:03 AM by tathamoddie


tathamoddie wrote Mar 14, 2011 at 1:30 PM

Hi Craig,

I can't reproduce this in the source. Tested against cbdf64bacd4e.

I've added a new test in 0318aadcf8fb to cover this scenario anyway:

public void MessageCoordinator_Publish_ShouldAcceptNewMessagesWithinACallback()
// Arrange
var coordinator = new MessageCoordinator();

// Act
var intReceived = false;
coordinator.Subscribe<int>(m => { intReceived = m == 123; });
coordinator.Subscribe<string>(m => coordinator.Publish(123));

// Assert

-- Tatham

craigathon wrote Mar 15, 2011 at 5:39 AM

Hi Tatham,
I was able to reproduce by executing the publish before the subscribe. So basically just flip the lines around.

coordinator.Subscribe<string>(m => coordinator.Publish(123));


tathamoddie wrote Mar 15, 2011 at 8:35 AM

Ah - it happens when we're playing back old messages (aka, the subscribe happens after the published).

Fixed + test added in f22fc40cd33e.

Thanks for your diagnosis. :)

tathamoddie wrote Mar 26, 2011 at 1:01 AM

Fix released in v1.1.

-- Tatham