This project has moved and is read-only. For the latest updates, please go here.


Messenger support for uncast objects


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 1:55 PM by lbugnion


SimpleNick wrote Aug 18, 2011 at 5:23 PM

To Replicate :
public class TestArgs {

public class Test : ViewModelBase {

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

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

        //will not send because message type is seen as object


    public void TestMethod(TestArgs args)


SimpleNick wrote Aug 25, 2011 at 9:24 PM

Hello ?

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

lbugnion wrote Aug 26, 2011 at 2:04 PM


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.


lbugnion wrote Sep 11, 2011 at 11:10 PM

Fixed in V4 beta 1

Necroman wrote Feb 19, 2016 at 2:12 PM

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: