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???
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???