Serialize Assembly to Stream and back again

  • Thread starter Thread starter Carl Gilbert
  • Start date Start date
C

Carl Gilbert

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.LoadFile("d:\test.dll")

Dim binFormatter As New Formatters.Binary.BinaryFormatter
Dim stream As New MemoryStream

binFormatter.Serialize(stream, myAssembly)

stream.Position = 0

Dim ass As [Assembly]
ass = binFormatter.Deserialize(stream)

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

Any help on this would be greatly appreciated.

Regards, Carl Gilbert
 
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!
 
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
 
Back
Top