Convert "Non Serializable" object to byte array

  • Thread starter Aneesh Pulukkul[MCSD.Net]
  • Start date
A

Aneesh Pulukkul[MCSD.Net]

How to convert a "Non Serializable" object to byte array. The object
is a dynamically created Excel workbook. As per my understanding an
object can be written and read from a stream Only if it's serialized.
Any ideas?

Thanks in advance.
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,
Aneesh Pulukkul said:
How to convert a "Non Serializable" object to byte array. The object
is a dynamically created Excel workbook. As per my understanding an
object can be written and read from a stream Only if it's serialized.
Any ideas?

If the object is not serializable then you will have to do it yourself. In
your particular case I do not see how you can do so (unless you have the
source code of the class you want to serialize).

Refering to your other question, an object can be readed/written to a stream
(or a file) if they provide methods for that.
 
N

Nicholas Paldino [.NET/C# MVP]

In this case, I would look to see if the object implements the
IPersistMemory interface. This is a COM interface (which I mention because
this is an Excel workbook, which is a COM object, ultimately) which allows
the state of the object to be persisted to unmanaged memory. You can then
marshal that to a managed byte array, or do whatever you wish with it.

You can also look for the IPersistFile interface, or the IPersistStream
interface, and see if the workbook supports those. Those will persist to a
file, and a stream (a COM IStream implementation).
 
A

Aneesh Pulukkul[MCSD.Net]

In this case, I would look to see if the object implements the
IPersistMemory interface. This is a COM interface (which I mention because
this is an Excel workbook, which is a COM object, ultimately) which allows
the state of the object to be persisted to unmanaged memory. You can then
marshal that to a managed byte array, or do whatever you wish with it.

You can also look for the IPersistFile interface, or the IPersistStream
interface, and see if the workbook supports those. Those will persist to a
file, and a stream (a COM IStream implementation).

--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.com> wrote in
message

If the object is not serializable then you will have to do it yourself. In
your particular case I do not see how you can do so (unless you have the
source code of the class you want to serialize).
Refering to your other question, an object can be readed/written to a
stream (or a file) if they provide methods for that.- Hide quoted text -

- Show quoted text -

Thank you guys for the info.
Regarding the Ipersismemory interface, I really don't know about the
interface. The definiton for workbook class is seen in the metadata:

[ClassInterface(0)]
[Guid("00020819-0000-0000-C000-000000000046")]

[ComSourceInterfaces("Microsoft.Office.Interop.Excel.WorkbookEvents")]
[TypeLibType(2)]
public class WorkbookClass : _Workbook, Workbook,
WorkbookEvents_Event


[CoClass(typeof(WorkbookClass))]
[Guid("000208DA-0000-0000-C000-000000000046")]
public interface Workbook : _Workbook, WorkbookEvents_Event


[Guid("000208DA-0000-0000-C000-000000000046")]
[TypeLibType(4160)]
public interface _Workbook
 

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