2

Closed

Messages Subscribe to interface calls both messageReceived and neverReceived callbacks

description

For an interface and messages like so:

public interface IMyMessage {
void Run();
}

public class MyMessage1 : IMyMessage {
public void Run() {
    // Do something...
}
}

public class MyMessage2 : IMyMessage {
public void Run() {
    // Do something...
}
}

If you subscribe to the interface:

Messages.Subscribe<IMyMessage>( m => {
// Got a message
}, () => {
// Didn't get a message
});

And then publish a message using inference for the Publish method's type parameter:
Messages.Publish(new MyMessage1());

Then both of the call backs will be called...

As a workaround, if you call Publish and specify the type parameter explicitly then this works as expected:
Messages.Publish<IMyMessage>(new MyMessage1());

I haven't looked at the code yet but I would guess it's an easy fix...
Closed Mar 26, 2011 at 12:03 AM by tathamoddie

comments

joshperry wrote Jul 30, 2010 at 11:15 PM

I believe the offending code is in MessageCoordinator.cs:
<code>
        var neverReceivedMessageTypes = neverReceivedCallbacks
            .Keys
            .Where(neverReceivedMessageType =>
                !messages.Keys.Any(messageType =>
                    messageType.IsAssignableFrom(neverReceivedMessageType)));
</code>

I believe it should be:

<code>
        var neverReceivedMessageTypes = neverReceivedCallbacks
            .Keys
            .Where(neverReceivedMessageType =>
                !messages.Keys.Any(messageType =>
                    neverReceivedMessageType.IsAssignableFrom(messageType)));
</code>

steve_godbold wrote Aug 4, 2010 at 2:00 PM

I've submitted the patch for this, just need to sign the appropriate doco to get it merged in.

Cheers,
Steve.

tathamoddie wrote Mar 14, 2011 at 12:32 PM

Fixed in 01d129c94898.

tathamoddie wrote Mar 14, 2011 at 12:32 PM

Fix shipped in 0.9.7.5.