469,366 Members | 2,254 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,366 developers. It's quick & easy.

Convert "Non Serializable" object to byte array

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.

Jun 8 '07 #1
5 20654
Hi,
"Aneesh Pulukkul[MCSD.Net]" <an******@gmail.comwrote in message
news:11**********************@q66g2000hsg.googlegr oups.com...
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.
Jun 8 '07 #2
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]
- mv*@spam.guard.caspershouse.com

"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.comwrote in
message news:Oh**************@TK2MSFTNGP02.phx.gbl...
Hi,
"Aneesh Pulukkul[MCSD.Net]" <an******@gmail.comwrote in message
news:11**********************@q66g2000hsg.googlegr oups.com...
>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.

Jun 8 '07 #3
On Jun 8, 7:33 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@spam.guard.caspershouse.comwrote:
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]
- m...@spam.guard.caspershouse.com

"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions.comwrote in
messagenews:Oh**************@TK2MSFTNGP02.phx.gbl. ..
Hi,
"Aneesh Pulukkul[MCSD.Net]" <anees...@gmail.comwrote in message
news:11**********************@q66g2000hsg.googlegr oups.com...
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.- 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.Exce l.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

Jun 8 '07 #4
Aneesh Pulukkul[MCSD.Net] wrote:
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 anything else fails then there are an idea for a workaround
illustrated here:

http://www.vajhoej.dk/arne/eksperten/ser/ser.cs
http://www.vajhoej.dk/arne/eksperten/ser/ser2.cs

Arne
Jun 9 '07 #5
On Jun 9, 5:28 am, Arne Vajhøj <a...@vajhoej.dkwrote:
Aneesh Pulukkul[MCSD.Net] wrote:
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 anything else fails then there are an idea for a workaround
illustrated here:

http://www.vajhoej.dk/arne/eksperten...en/ser/ser2.cs

Arne
Thanks Arne for the code snippet.

Jun 9 '07 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by JKop | last post: by
1 post views Thread by Mat DeLong | last post: by
15 posts views Thread by Sander Tekelenburg | last post: by
5 posts views Thread by Verde | last post: by
8 posts views Thread by Bern McCarty | last post: by
3 posts views Thread by Arnost Sobota | last post: by
2 posts views Thread by Ken Tilton | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.