By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,344 Members | 1,114 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,344 IT Pros & Developers. It's quick & easy.

SerlializationException

P: n/a
I am serializing a some objects and inserting them into a database,
then retrieving them afterwards.
Serializing (using a BinaryFormatter) and storing the objects seems to
give me no problems, but when I try to deserialize, I get "The input
stream is not a valid binary format." exception (followed by a long
string of bytes that represent the object and it seems to be correct).
What is really puzzling me is that I ran a test and when I deserialize
the objects immediately (that is, I don't store them to the database, I
just deserialize them right away), everything seems to work fine. I
only seem to have problems when one procedure serializes the object and
stores it in the database, and another one retreives it from the
database and deserializes it.

Oh yeah, the database I am using is SQL Server 2005, and the objects
are stored in fields of type varbinary(max).

Are there any experts out there on VB Serialization who could help? I'm
still kinda new to this...

thanks. ;)

Nov 17 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a

lo*********@gmail.com wrote:
I am serializing a some objects and inserting them into a database,
then retrieving them afterwards.
Serializing (using a BinaryFormatter) and storing the objects seems to
give me no problems, but when I try to deserialize, I get "The input
stream is not a valid binary format." exception (followed by a long
string of bytes that represent the object and it seems to be correct).
What is really puzzling me is that I ran a test and when I deserialize
the objects immediately (that is, I don't store them to the database, I
just deserialize them right away), everything seems to work fine. I
only seem to have problems when one procedure serializes the object and
stores it in the database, and another one retreives it from the
database and deserializes it.

Oh yeah, the database I am using is SQL Server 2005, and the objects
are stored in fields of type varbinary(max).

Are there any experts out there on VB Serialization who could help? I'm
still kinda new to this...

thanks. ;)
Just a guess, but I think there is something wrong with either you
storage or retrieval code. In other words, I don't think you getting
it all back from the db. Can you post some minimal code that
demonstrates the whole process (storage and retrieval) that gets the
error?

--
Tom Shelton

Nov 17 '06 #2

P: n/a
Tom,

I thought will I answer it, but than I thought, I should wait, maybe Tom
comes around, this is his part in this newsgroup.

Is it not awfull late for you?

Cor

"Tom Shelton" <to*********@comcast.netschreef in bericht
news:11**********************@e3g2000cwe.googlegro ups.com...
>
lo*********@gmail.com wrote:
>I am serializing a some objects and inserting them into a database,
then retrieving them afterwards.
Serializing (using a BinaryFormatter) and storing the objects seems to
give me no problems, but when I try to deserialize, I get "The input
stream is not a valid binary format." exception (followed by a long
string of bytes that represent the object and it seems to be correct).
What is really puzzling me is that I ran a test and when I deserialize
the objects immediately (that is, I don't store them to the database, I
just deserialize them right away), everything seems to work fine. I
only seem to have problems when one procedure serializes the object and
stores it in the database, and another one retreives it from the
database and deserializes it.

Oh yeah, the database I am using is SQL Server 2005, and the objects
are stored in fields of type varbinary(max).

Are there any experts out there on VB Serialization who could help? I'm
still kinda new to this...

thanks. ;)

Just a guess, but I think there is something wrong with either you
storage or retrieval code. In other words, I don't think you getting
it all back from the db. Can you post some minimal code that
demonstrates the whole process (storage and retrieval) that gets the
error?

--
Tom Shelton

Nov 17 '06 #3

P: n/a

Cor Ligthert [MVP] wrote:
Tom,

I thought will I answer it, but than I thought, I should wait, maybe Tom
comes around, this is his part in this newsgroup.

Is it not awfull late for you?
I guess. I am trying to be "around" more - but, things seem to be not
going my way the last year of so, when it comes to time for the news
groups :) About a year ago, we bought an old farm house and it has
been really keeping me busy when I'm not at work. Also, I just changed
jobs after eight years with my last employer - boy was that traumatic
(but good)! So, I come around when I can. And answer what I have time
for - which just isn't much lately.

--
Tom Shelton

Nov 17 '06 #4

P: n/a
Just a guess, but I think there is something wrong with either you
storage or retrieval code. In other words, I don't think you getting
it all back from the db. Can you post some minimal code that
demonstrates the whole process (storage and retrieval) that gets the
error?

--
Tom Shelton
Here's the serizlization code:
Dim serializer As New
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter
Dim objStream As New System.IO.MemoryStream

serializer.Serialize(objStream, uiObj)
Dim hexStr As String = ""
'convert each serialization to a hex string
For Each b As Byte In objStream.ToArray
hexStr &= byteToHexString(b) 'quick 'n' dirty function returns hex
rep of a byte.
Next

'now, send each data to the database.
db_query.execute("EXEC insert_blob @name='" & blobName & "', @data=0x"
& hexStr)
-----
and here's the deserialization code:

db_query.execute("EXEC get_saved_blob @name='" & tmpName & "'",
blob_table)
'check to see if there are any parts in the search
If blob_table.Rows.Count 0 Then
Dim serializer As New
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter
For Each blob_row As Data.DataRow In blob_table.Rows
Dim blobStream As New System.IO.MemoryStream
For Each b As Byte In blob_row.Item("search_blob")
'write the bytes to the stream.
blobStream.WriteByte(b)
Next
blobStream.Position = 0
uiPanel.Controls.Add(CType(serializer.Deserialize( blobStream),
Windows.Forms.Control))
Next
End If

-----

I have a hunch that the code in the deserialization might be broken,
but I'm just not sure.

Thanks.

Nov 20 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.