tags:

views:

16

answers:

1

Hi,

I am trying to send the message(complex type) to the message queue.I am getting the error,ETravel.Web, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable.below lies the code for that.

 public void QueueMessage(EmailMessage message)
        {
            Message msg = new Message();
            msg.Body = message;
            msg.Recoverable = true;
            msg.Formatter = new BinaryMessageFormatter();
            string queuePath = @".\private$\WebsiteEmails";
            //InsureQueueExists(queuePath);
            MessageQueue msgQ;
            msgQ = new MessageQueue(queuePath);
            msgQ.Formatter = new BinaryMessageFormatter();
            msgQ.Send((object)msg);
        }

The complex type EmailMessage is as follows.

public class EmailMessage
    {
        public string subject { get; set; }
        public string message { get; set; }
        public string from { get; set; }
        public string to { get; set; }
    }

Thanks in Advance.

I have installed the MessageQueue.

O/s: windows xp.
Technology Used:Asp.net mvc.

A: 

Did you mark this class as [Serializable]?

 [Serializable]
 public class EmailMessage
 { ..... }

Also you have no methods to serialize it You should tell how to use serialize your object as you're using non built-in object

//Deserialization
public EmailMessage(SerializationInfo info, StreamingContext ctxt)
{


to = (string)info.GetValue("to", typeof(string));
from = (String)info.GetValue("from", typeof(string));
// add other stuff here
}

//Serialization function.

public void GetObjectData(SerializationInfo info, StreamingContext ctxt)
{

// then you should read the same with "EmployeeId"

info.AddValue("to", to);
info.AddValue("from", from);
}

Edit: Sorry I was thinking of BinaryFormatter not BinaryMessageFormatter. Though you can still try it and see whether it works.

regards

nomail