"Mark Rae" <ma**@markrae.co.uk> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
According to Joe Mayo, the MailMessage type is not serializable...
This is the code I'm trying to use:
MailMessage objMailMessage = new MailMessage();
try
{
MemoryStream objMS = new MemoryStream();
BinaryFormatter objBinaryFormatter = new BinaryFormatter();
objBinaryFormatter.Serialize(objMS, objMailMessage); // error
thrown on this line
byte[] abytMailMessage = objMS.GetBuffer();
}
catch (Exception ex)
{
//write to EventLog
throw(ex);
}
ex.ToString() reveals the error details below:
System.Runtime.Serialization.SerializationExceptio n: The type
System.Web.Mail.MailMessage in Assembly System.Web, Version=1.0.5000.0,
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a is not marked as
serializable.\r\n at
System.Runtime.Serialization.FormatterServices.Int ernalGetSerializableMember
s(RuntimeType type, Boolean excludeNonSerializable)\r\n at
System.Runtime.Serialization.FormatterServices.Get SerializableMembers(Type
type, StreamingContext context)\r\n at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.InitMemberInf
o()\r\n at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.InitSerialize
(Object obj, ISurrogateSelector surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)\r\n at
System.Runtime.Serialization.Formatters.Binary.Wri teObjectInfo.Serialize(Obj
ect obj, ISurrogateSelector surrogateSelector, StreamingContext context,
SerObjectInfoInit serObjectInfoInit, IFormatterConverter converter)\r\n at
System.Runtime.Serialization.Formatters.Binary.Obj ectWriter.Serialize(Object
graph, Header[] inHeaders, __BinaryWriter serWriter, Boolean fCheck)\r\n at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Serialize(Str
eam serializationStream, Object graph, Header[] headers, Boolean fCheck)\r\n
at
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter.Serialize(Str
eam serializationStream, Object graph)\r\n at
TestEmail.WebForm1.Page_Load(Object sender, EventArgs e) in
c:\\inetpub\\wwwroot\\testemail\\webform1.aspx.cs: line 29"