473,734 Members | 2,511 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Deserialize problem

I have 2 solution to deserialize ArrayList which contains objects
I am using for this MemoryStream, but MemoryStream is not functional - I
receive always error
#End of Stream encountered before parsing was completed.#

The second solution is functionall - I am using in this solution
FileStream - everything works fine !!
I want to use MemoryStream instead of FileStrem
Can somebody tells me where I have problem ?
I am using the same source: byte array Dim bytes() As Byte
Thanks
############### ##### First solution with ERROR ############

Dim bytes() As Byte = row("PANEL_DATA ") 'DataRow, column PANEL_DATA

Dim bFormatter As New BinaryFormatter ()
Dim ms As MemoryStream
Dim b As Byte
ms = New MemoryStream()
ms.SetLength(by tes.Length)
Dim i As Int32
For i = 0 To bytes.Length - 1
ms.WriteByte(by tes(i))
Next

Try
########### in this line is error ###############
Me.objList = bFormatter.Dese rialize(ms)
Catch ex As Exception
ms.Close()
gShowError(ex, "LoadControlsSe r - deserialize")
End Try
ms.Close()

############### ##### Second solution - working solution ############

Dim ms As New MemoryStream()
Dim bFormatter As New BinaryFormatter ()
ms.Write(bytes, 0, bytes.Length)
Dim stream11 As Stream = New FileStream("C:\ MyFile.bin", FileMode.Create ,
FileAccess.Writ e, FileShare.None)
stream11.Write( bytes, 0, bytes.Length)
stream11.Close( )
Try
Dim formatter As BinaryFormatter = New BinaryFormatter ()
Dim stream22 As Stream = New FileStream("C:\ MyFile.bin", FileMode.Open,
FileAccess.Read , FileShare.Read)
Me.objList = formatter.Deser ialize(stream22 )
stream22.Close( )
Catch ex As Exception
gShowError(ex, "LoadControlsSe r")
Return False
End Try

Return True
Tomas Oplt

Tel: 603 171893

Nov 20 '05 #1
1 2132
In article <e5************ **@TK2MSFTNGP12 .phx.gbl>, Pavel Pavel wrote:
I have 2 solution to deserialize ArrayList which contains objects
I am using for this MemoryStream, but MemoryStream is not functional - I
receive always error
#End of Stream encountered before parsing was completed.#

The second solution is functionall - I am using in this solution
FileStream - everything works fine !!
I want to use MemoryStream instead of FileStrem
Can somebody tells me where I have problem ?
I am using the same source: byte array Dim bytes() As Byte
Thanks
############### ##### First solution with ERROR ############

Dim bytes() As Byte = row("PANEL_DATA ") 'DataRow, column PANEL_DATA

Dim bFormatter As New BinaryFormatter ()
Dim ms As MemoryStream
Dim b As Byte
ms = New MemoryStream()
ms.SetLength(by tes.Length)
Dim i As Int32
For i = 0 To bytes.Length - 1
ms.WriteByte(by tes(i))
Next


You could do away with the above... You can create a memory stream from
the byte array directly :)

Dim bytes() As Byte = row("PANEL_DATA ")
Dim bFormater As New BinaryFormatter ()
Dim ms As New MemoryStream(ms )

Try
Me.objList = bFormatter.Dese rialize(ms)
Catch ex As Exception
gShowError(ex, "LoadControlsSe r - deserialize")
Finally
ms.Close()
End Try
That should work :) In your old solution, though - you need to add this
line right after the loop.

ms.Seek(0, SeekOrigin.Begi n)

ms.WriteByte was moving the current pointer down the stream, so when you
call deserialize - the pointer is at the end of the stream.
--
Tom Shelton
MVP [Visual Basic]
Nov 20 '05 #2

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

Similar topics

1
570
by: Carl Mercier | last post by:
Hi! I have 2 different applications/assembly. The first one creates an object and serializes it to a textfile on disk. The second one has the the exact same class (copied/pasted). It reads the file that is on disk and attempts to deserialize it and create a new object. The process works fine if I serialize/deserialize in the first
3
5881
by: Amsteel | last post by:
I got something like this in VB.Net <Serializable()> Public Class YQProfileC Inherits CollectionBase Public Sub Save2File(ByVal FileName As String) Dim IFormatter As New BinaryFormatter() Dim FS As FileStream = New FileStream(FileName, FileMode.Create, FileAccess.Write, FileShare.None) IFormatter.Serialize(FS, Me) FS.Close()
2
6071
by: PCH | last post by:
I have 2 functions, one to serialize an object, and one to deserialize it. I can serialize just fine, the problem is when I try to deserialize it later... I get an error: {"Invalid BinaryFormatter stream. " } I looked at the serialized string vs whats passed into the deserialize
2
2427
by: alexandre martins | last post by:
Every time i try to make Deserialize the computer gives me the folowing error: "End of Stream encountered before parsing was complete" the code that i'm running is simple and is based on an MSDN example. The CODE is BELOW this lines. If you see something wrong or missing please answer. Class declaration:
4
3569
by: Samuel R. Neff | last post by:
I'm deserializing an XML file. If I pass a Stream to the file directly to the deserializer as follows it works fine: o = (New XmlSerializer( GetType( CompensationPackage))).Deserialize(stream) But if I pass an XmlNodeReader to the deserializer it doesn't work:
2
11536
by: Thomas S | last post by:
Any suggestions on how to deserialize an object from one line of XML? I'm trying to deserialize multiple objects from one XML document, each object on one line of the file. The serialization is working, but when I try to read the line back into a MemoryStream, and then to deserialize from that, I get an error that the root node doesn't exist. Example XML lines: <?xml version="1.0"?><LogItem
1
7886
by: Heron | last post by:
Hi, I'm having a problem deserializing my streams since they are utf8 encoded (they are being received over tcp/ip) so I was looking for a way to make the serializer use utf8, is there any? I'm getting the following error: There is an error in XML document (0, 0). innerexception: There is no Unicode byte order mark. Cannot switch to Unicode."
11
2817
by: wpmccormick | last post by:
I've a complex problem: I'm deserializing a very long string of XML into a very large object foo: <foo> ....... <bar>sometimes a simple string is here</bar> ....... </foo>
0
2251
by: connectpalm03-forum | last post by:
I have a class named (MyClassA) in ControlClasses.dll and was able to serialize it to database. Like below SaveTo(MemoryStream stream) { IFormatter formatter = new BinaryFormatter(); formatter.Serialize(stream, this); }
0
8946
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
9310
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
9236
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
9182
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
8186
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
6735
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
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
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
2724
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.