Hi Folks,
I got a problem with message queue. I want to put a row of a dataset into
the message body and when I send it to the Q I throws an Exception.
Error message is : YNOTCALLME.MULTISOFT.ENTITY.dsDistributor.DistributorRow
cannot be serialized because it does not have a default public constructor
I have the following methos which throw the exception:
private void
Send2VoiceRoomQ(YNOTCALLME.MULTISOFT.ENTITY.dsDistributor.DistributorRow
row)
{
try
{
if(MessageQueue.Exists(VOICEQ))
{
//creates an instance MessageQueue, which point to the already existing
MyQueue
mqv = new System.Messaging.MessageQueue(VOICEQ);
}
else
{
//creates a new private queue called VOICEQ
mqv = MessageQueue.Create(VOICEQ);
}
mqv.Formatter = new System.Messaging.XmlMessageFormatter();
for ( int i=0; i < dsDistibutor.Distributor.Rows.Count ; i++ )
{
System.Messaging.Message mm = new System.Messaging.Message();
mm.Label = row["dm_lname"].ToString () + " " + row["dm_fname"].ToString () ;
mm.Body = row;
mqv.Send(mm);
}
}
catch( Exception ex )
{
FRAMEWORK.ERRORMANAGER.Error.Save (ex.Message,ex.Source ,ex.StackTrace ,"");
}
}
What I would like to achive is put a row of the dataset into the message and
send it to the MSMQ.
Any idea if is that possible?
Thanks
Laszlo
Klaus H. Probst - 25 Jan 2005 06:36 GMT
A DataRow will not serialize "just like that". You need to do it manually,
for example to a Hashtable or something similar. Is the row on a dataset?
That might be easier since that can be treated as XML.
MSMQ is telling you that it can't serialize the object, and more
importantly, it would not be able to deserialize it when the message is
retrieved from the queue.

Signature
Klaus H. Probst, MVP
http://www.simulplex.net/
> Hi Folks,
>
[quoted text clipped - 73 lines]
>
> Laszlo
Cordell Lawrence - 23 Apr 2005 21:59 GMT
There are actually several ways that come to mind that this can be dealt
with.
1. Serialize the object yourself. Create another data structure (like a
struct or class) that takes the properties of the row and stores it as its
state. then serialize that object.
2. Create a public parameterless constructor on you strongly typed row
object by editing and rebuilding the code that is produced by V. Studio for
strongly typed data sets. This one becomes problematic if the dataset isn't
set in stone, when you make changes to the schema of your strongly typed
dataset VS regens the class code that represents you strongly typed data set
and then *poff* your code changes disappear.
3. You can create you own Formatter object that implements IMessageFormatter
that is able to (serialize and deserialize) your Row object and pass that to
you message queue instance.
The last is probably the best choice, in my opinion.
HTH
Cordell Lawrence
Teleios Systems Ltd.
> Hi Folks,
>
[quoted text clipped - 73 lines]
>
> Laszlo