473,811 Members | 3,521 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Serialize Assembly to Stream and back again

Hi

I am trying to serialize an assembly into a byte array. I am using a
BinaryFormatter to serialize the assembly into a stream. Once in the
stream, would then save this to the database in a byte().

I have come across a few issues with deserializing the stream so I decided
to strip out all the un-necessary code and simply serialize from an assembly
to a stream and then de-serialize is back again using the same
BinaryFormatter .

However, I get the following error:

SaveGUI: Insufficient state to deserialize the object. More information
is needed.

With the following code:

Try
Dim myAssembly As [Assembly]
myAssembly = myAssembly.Load File("d:\test.d ll")

Dim binFormatter As New Formatters.Bina ry.BinaryFormat ter
Dim stream As New MemoryStream

binFormatter.Se rialize(stream, myAssembly)

stream.Position = 0

Dim ass As [Assembly]
ass = binFormatter.De serialize(strea m)

Catch ex As System.Exceptio n
Debug.WriteLine (ex.Message, "SaveGUI")
End Try

Any help on this would be greatly appreciated.

Regards, Carl Gilbert
Jul 21 '05 #1
2 2639
Hi,

why not just use the System.IO classes to read the FileStream of the DLL and
write out the bytes in Base64Encoding to XML. It might be a better option!
Jul 21 '05 #2
The LoadFile is just being used to ensure that a good assembly was being
used. In reality, I will be getting the Assembly at runtime.
The problem is that when I have an Assembly that I know is good, I can not
get back the same assembly after the serialization/de-serialization.
I feel that I am missing something on the serialize settings.

Regards, Carl
"Saurabh Nandu" <Sa**********@d iscussions.micr osoft.com> wrote in message
news:4A******** *************** ***********@mic rosoft.com...
Hi,

why not just use the System.IO classes to read the FileStream of the DLL
and
write out the bytes in Base64Encoding to XML. It might be a better option!

Jul 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
24735
by: David Sworder | last post by:
Hi, I've created a UserControl-derived class called MyUserControl that is able to persist and subsequently reload its state. It exposes two methods as follows: public void Serialize(Stream s); public void Deserialize(Stream s); Within the MyUserControl class, there is a field of type MyInnerClass
5
2556
by: andrewcw | last post by:
I have an object to serialize. TextWriter writer = new StreamWriter("test.xml"); serializer.Serialize(writer,obj); writer.Close(); but below does not, why ?? I have a file that I will have exclusively opened & I use the stream for that operation. THANKS { I am tring to push the object back into the stream )
10
4179
by: Dan | last post by:
All I Am Attempting To Serialize An Object To An XML File. Here Is The Code For That public string SaveNewSurvey( MutualSurveyObject mso_TempObject, int i_JobID ) { string s_RootFileName; string s_FinalFileName; try
3
10391
by: MAY | last post by:
Hi, I have a problem about serialize the form controls. I wrote a test program to test serialize a from but fail (->An unhandled exception of type 'System.Runtime.Serialization.SerializationException' occurred in mscorlib.dll) . Thx in advance. Here is the part of the code: Regards MAY
0
1774
by: Fred Heida | last post by:
Hi Al, i have a funny problem.. i you can call it funny.. what i have is 2 assemblies, the first one does nothing other then Application.Run(new MyForm())
2
8894
by: films | last post by:
I understand the concept. Serialization of a class will add all the sub-objects of the class to the stream if there are also serializible. So say I have: class Author {
5
2390
by: objectref | last post by:
Hi to all, let's say i have a form with 2 buttons and 3 textboxes on it. Is there a way to Serialize the form so when i de-Serialize and cast it to a Form, i will get back the original form with the textboxes filled with their original values ?? I have built an app that i want to have the values of many-many forms' controls on the disk and then all the values back to the forms,
2
435
by: Carl Gilbert | last post by:
Hi I am trying to serialize an assembly into a byte array. I am using a BinaryFormatter to serialize the assembly into a stream. Once in the stream, would then save this to the database in a byte(). I have come across a few issues with deserializing the stream so I decided to strip out all the un-necessary code and simply serialize from an assembly to a stream and then de-serialize is back again using the same BinaryFormatter.
1
39710
by: Tim | last post by:
Could anyone tell me what this means and how do I correct it. Any suggestions? Thanks! Tim Richardson IT Developer and Consultant www.paladin3d.com Unable to serialize the session state. In 'StateServer' and 'SQLServer' mode, ASP.NET will serialize the session state objects, and as a result non-serializable objects or MarshalByRef objects are not permitted. The same
0
9726
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9605
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
10647
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...
1
10395
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
10130
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9204
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7667
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.