Deseralization problem...

G

Guest

I have a mail class which is extended from Outlook.MailItem like below to
make it serializable

[Serializable]
public class myMail : ISerializable
{
Outlook.MailItem Mail;
public myMail(Outlook.MailItem Mail)
{
this.Mail = Mail;
}

public Outlook.MailItem getMail()
{
return Mail;
}

void ISerializable.GetObjectData(SerializationInfo info,
StreamingContext context)
{

}
}

I serialize the object which is created by it with the below function

public byte[] getByteArrayWithObject(Outlook.MailItem o)
{
MemoryStream ms = new MemoryStream();
BinaryFormatter bf1 = new BinaryFormatter();
myMail myo = new myMail(o);
bf1.Serialize(ms, myo);
return ms.ToArray();
}

Then again I create a MailItem object with this code

Outlook.MailItem mailItem =
(Outlook.MailItem)this.CreateItem(Outlook.OlItemType.olMailItem);

myMail myDeserializedMail = new myMail(mailItem);

And then i want to deserialize the object which i get from db (in binary
form) with the below code

public object getObjectWithByteArray(byte[] theByteArray)
{
MemoryStream ms = new MemoryStream(theByteArray);
BinaryFormatter bf1 = new BinaryFormatter();
ms.Position = 0;

return bf1.Deserialize(ms);
}

--> getObjectWithByteArray(blob);

But at this moment i raises exception that

"ex = {"The constructor to deserialize an object of type 'GetMail.myMail'
was not found."}"

What can i do???
 
A

Adam Benson

Usually a class that has manual serialisation (where you have a routine that
does the serialising for you - your GetObjectData method) needs a ctor that
looks something like this :

protected MyClass(SerializationInfo info, StreamingContext context)

{

myint64 = info.GetInt64("f1");

mybool = info.GetBoolean("b1");

}

You might try sticking a default ctor in, as well

i.e.

public MyClass()



Try this. HTH,



Adam.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top