This project has moved. For the latest updates, please go here.
1

Closed

Messenger support for uncast objects

description

I was trying to send messages created by the Activator.CreateInstance (as opposed to using new) via the messenger without success.

Upon inspection, I notice that my message instance was of type "object { MyNamespace.MyClass }" as opposed to "MyNamespace.MyClass".

I am using the Activator to create my messages because my messages are coming from a Socket / deserialization implementation.

changing the following in the Messenger.cs would fix my issue :
    private void SendToTargetOrType<TMessage>(TMessage message, Type messageTargetType, object token)
    {
        var messageType = typeof(TMessage);

to :
     private void SendToTargetOrType<TMessage>(TMessage message, Type messageTargetType, object token)
    {
        //Type messageType = typeof(TMessage);
        Type messageType = message.GetType();
would help me.

file attachments

Closed Oct 13, 2014 at 12:55 PM by lbugnion

comments

SimpleNick wrote Aug 18, 2011 at 4:23 PM

To Replicate :
public class TestArgs {
}

public class Test : ViewModelBase {

    public Test()
    {
        //register
        MessengerInstance.Register<TestArgs>(this, TestMethod);

        object message = Activator.CreateInstance(typeof(TestArgs));


        //will not send because message type is seen as object
        MessengerInstance.Send(message);

    }

    public void TestMethod(TestArgs args)
    {
    }

}

SimpleNick wrote Aug 25, 2011 at 8:24 PM

Hello ?

A simple Yes, No would be cool. Its been a week

lbugnion wrote Aug 26, 2011 at 1:04 PM

Hi,

Sorry for the delay. I happen to have a life ;) and in that life, I moved to a new house last week and had to handle my kids starting in a new school.

Your proposal seems straightforward enough. I need to check that there are no unwanted side effects, and I should be able to push it in V4 beta 1, which will come out as soon as I sort a couple of issues with the installer.

Cheers,
Laurent

lbugnion wrote Sep 11, 2011 at 10:10 PM

Fixed in V4 beta 1

Necroman wrote Feb 19, 2016 at 1:12 PM

Hi,
not sure, if this is by design or it's still this bug unfixed, but when sending CustomMessage type saved into temporary variable of type MessageBase, then it's not delivered to listeners of type CustomMessage.

See the simple repro in the attachment: