472,353 Members | 2,007 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,353 software developers and data experts.

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 21024
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: JKop | last post by:
Would you classify the following code as "Undefined Behaviour" or as "Non- portable"? signed main() { signed char chedder = 130; } ...
1
by: Mat DeLong | last post by:
Can someone explain this error to me? : main.cpp:9: instantiated from `void show(const LIST::List<T>&) ' main.cpp:23: instantiated from here...
15
by: Sander Tekelenburg | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 The HTML specs speak of "replaced" and "non-replaced" elements, yet for the life of me I can't...
6
by: Hardy Wang | last post by:
Hi all: The Stream object from WebRequest.GetResponseStream() is non-seekable. How can I convert this stream to a byte array? For ordinary...
5
by: Verde | last post by:
I'm using a 3rd party component in an ASP.NET 1.1 Web application. The component has a .Click event that can be fired from the client, with an...
8
by: Bern McCarty | last post by:
Is it at all possible to leverage mixed-mode assemblies from AppDomains other than the default AppDomain? Is there any means at all of doing this?...
3
by: Arnost Sobota | last post by:
Dear ASP community, I have a question regarding ASP session variables. My assumption was that a session variable has the same lifetime as the...
2
by: Ken Tilton | last post by:
Total JS noob here, but porting my hairy Common Lisp Cells (dataflow) package -- long intro on my blog: ...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.