473,770 Members | 4,999 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 21240
Hi,
"Aneesh Pulukkul[MCSD.Net]" <an******@gmail .comwrote in message
news:11******** **************@ q66g2000hsg.goo glegroups.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.co m

"Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions .comwrote in
message news:Oh******** ******@TK2MSFTN GP02.phx.gbl...
Hi,
"Aneesh Pulukkul[MCSD.Net]" <an******@gmail .comwrote in message
news:11******** **************@ q66g2000hsg.goo glegroups.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.guar d.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.c om

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

[ComSourceInterf aces("Microsoft .Office.Interop .Excel.Workbook Events")]
[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(416 0)]
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.d kwrote:
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
2128
by: JKop | last post by:
Would you classify the following code as "Undefined Behaviour" or as "Non- portable"? signed main() { signed char chedder = 130; } Relevant information:
1
1858
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 list.cpp:58: error: dependent-name `LIST::List<T>::ListIterator' is parsed as a non-type, but instantiation yields a type .......... This is the first part of the main:
15
2851
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 find an explanation of what "replaced" is supposed to mean in this context. Can someone explain? TIA
6
52269
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 Stream (seekable), I can use StreamObject.Read(myByteArray, 0, myLength) --
5
2041
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 associated event procedure in the code-behind module. The logic in the click event procedure may, under some conditions, need to abort further processing. AFAIK the control's event is not cancellable. At least its EventArgs does not have any apparent support for .Cancel. So, what can I do to...
8
3514
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? Mixed-mode is incredibly convenient, but if I cannot load/unload/reload extensions into my large and slow-to-load application during development without restarting the process then the disadvantages may outweigh the advantages. I've got a mixed-mode program in which I create a new AppDomain...
3
2124
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 session itself: as a consequence, given that closing the browser doesn't terminate the session, the session variable is kept alive until the session expires. But, surprisingly, I've found this to be true for the session variables
2
2050
by: Ken Tilton | last post by:
Total JS noob here, but porting my hairy Common Lisp Cells (dataflow) package -- long intro on my blog: http://smuglispweeny.blogspot.com/2008/02/cells-manifesto.html ....so I am getting into some fun stuff straight-away. I am happy to see _defineGetter_/Setter_ here: http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Reference:Global_Objects:Object
0
9425
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10231
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10059
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10005
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
6679
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5313
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3972
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3576
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2817
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.