I am working on a website which is being developed in Visual Studio 2010 with ASP.NET 4.
I am trying to programmatically extract an image from a word document. The approach I am using is this:
- Convert WordApp.InlineShapes[1] (System._COM Object) to a byte[]
- Convert byte[] to an System.Drawing.Image object
- Save the image
But I am getting following exception in step1 itself:
Type 'System.__ComObject' in Assembly 'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable.
I googled for two days but unable to understand the problem and the workaround as I am quiet new to developement in ASP.NET
The line that I am executing is this:
byte[] shapeByteArray = ObjectToByteArray(wrdDoc.InlineShapes[1]);
The method ObjectToByteArray is as follows:
private byte[] ObjectToByteArray(Object obj)
{
if (obj == null)
return null;
BinaryFormatter bf = new BinaryFormatter();
MemoryStream ms = new MemoryStream();
bf.Serialize(ms, obj);
return ms.ToArray();
}
Following line is throwing the SerializationException:
return ms.ToArray();
Can you guys please help me understand and solve this issue?