Error while trying to convert the Aspose word doc to binary array

Hi,
I am getting the belwo erro while trying to convert the Aspose word doc to binary array.
Error: Type ‘Aspose.Words.Document’ in Assembly ‘Aspose.Words, Version=10.0.0.0, Culture=neutral, PublicKeyToken=716fcc553a201e56’ is not marked as serializable.
This is my code for converting the aspose doc object to binary array:

public byte[] ObjectToByteArray(object _Object)
{
    try
    {
        System.IO.MemoryStream _MemoryStream = new System.IO.MemoryStream();
        System.Runtime.Serialization.Formatters.Binary.BinaryFormatter _BinaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();//Error hitting here.
        _BinaryFormatter.Serialize(_MemoryStream, _Object);
        return _MemoryStream.ToArray();
    }
    catch (Exception ex)
    {
        throw ex;
    }
    return null;
}

Please suggest.
I have to convert the doc object to binary array and pass it through a web service.
Thanks,
Nik

Hi
Thanks for your request. The problem occurs because you are trying to serialize Aspose.Words.Document object, but Document is not serializible. To convert Document object to byte array you should just save your document into MemoreyStream and then extract byte array from this stream. For instance, see the following code:

Document doc = new Document("in.doc");
MemoryStream outStream = new MemoryStream();
// Save document to stream.
doc.Save(outStream, SaveFormat.Doc);
// Return byte array.
byte[] docBytes = outStream.ToArray();

Best regards,