Serialization


Author
Message
Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Trent,

The problem is with DeserializeBusinessObject. In your test did you try loCustomers1 = CustomersBO.DeserializeBusinessObject(memString)

'De-serialize the Business Object

Private Sub DeserializeMethod(ByVal memString As System.IO.MemoryStream)

     '-- Establish Lcoals

     Dim loCustomers1 As New CustomersBO

     '-- Deserialize the saved business object from a stream

     loCustomers1 = CustomersBO.DeserializeBusinessObject(memString)

End Sub

I can not post a sample right now because I am not in the office, but I would appreciate if you can try deserializing the memory stream.

Thanks!

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
You are welcome to post a sample reproducing the error, because I just tested this and it works fine.  So there must be something else going on within your environment.  I just did this and it worked:

Dim mem As New System.IO.MemoryStream()
Me.CustomerBO1.SerializeToStream(mem)


Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Edhy Rijo (03/11/2009)
I am trying to use the BO.SerializeToStream and DeserializeBusinessObject based on the error in the previous post, but I am hitting an error.  Here is the version of the code I am using:

Sorry, the highlighted phrase should have said: based on the code...

Edhy Rijo

Edhy Rijo
E
StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)StrataFrame VIP (6.4K reputation)
Group: StrataFrame Users
Posts: 2.4K, Visits: 23K
Hi Trent,

I am trying to use the BO.SerializeToStream and DeserializeBusinessObject based on the error in the previous post, but I am hitting an error.  Here is the version of the code I am using:

Private Sub SerializeMethod()

     '-- Establish Locals

     Dim memString As New System.IO.MemoryStream

     Dim loCustomers As New CustomersBO()

     '-- Load some data into the business object

     loCustomers.FillAll()

     '-- Serialize the business object to the stream

     loCustomers.SerializeToStream(memString)

     '-- Close the stream

     memString.Close()

     '-- Close the BO

     loCustomers.Dispose()

     Me.DeserializeMethod(memString)

End Sub

'De-serialize the Business Object

Private Sub DeserializeMethod(ByVal memString As System.IO.MemoryStream)

     '-- Establish Lcoals

     Dim loCustomers1 As New CustomersBO

     '-- Deserialize the saved business object from a stream

     loCustomers1 = CustomersBO.DeserializeBusinessObject(memString)

End Sub

Here is the stack error:

ArgumentException
  Stream was not readable.

Source     : mscorlib

Stack Trace:
   at System.IO.BinaryReader..ctor(Stream input, Encoding encoding)
   at System.Runtime.Serialization.Formatters.Binary.__BinaryParser..ctor(Stream stream, ObjectReader objectReader)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, Boolean isCrossAppDomain, IMethodCallMessage methodCallMessage)
   at System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.Deserialize(Stream serializationStream, HeaderHandler handler, Boolean fCheck, IMethodCallMessage methodCallMessage)
   at MicroFour.StrataFrame.Business.BusinessLayer.DeserializeBusinessObject(Stream InputStream)
   at CollisionTest.testForm.DeserializeMethod(MemoryStream memString) in E:\Visual Studio 2008 Projects\StrataFrame\Samples\AutoCompleteTest\AutoCompleteTest\TestForm.vb:line 41
   at CollisionTest.testForm.SerializeMethod() in E:\Visual Studio 2008 Projects\StrataFrame\Samples\AutoCompleteTest\AutoCompleteTest\TestForm.vb:line 31
   at CollisionTest.testForm.Button1_Click(Object sender, EventArgs e) in E:\Visual Studio 2008 Projects\StrataFrame\Samples\AutoCompleteTest\AutoCompleteTest\TestForm.vb:line 11
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
   at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ButtonBase.WndProc(Message& m)
   at System.Windows.Forms.Button.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativewindow.WndProc(Message& m)
   at System.Windows.Forms.Nativewindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Testing with System.IO.FileStream works just fine, what do I need to make it work with a System.IO.MemoryStream?

Edhy Rijo

Trent Taylor
Trent Taylor
StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)StrataFrame Developer (14K reputation)
Group: StrataFrame Developers
Posts: 6.6K, Visits: 7K
There are two serialization methods on a business object: SerializeToStream and SerialzieToByteArray. These work just as the names state. SerializeToStream supports any stream type such as a network stream, file stream, memory stream, etc. Here is a sample of serializing a business object and then de-serializing it. I am using a file stream here for sample purposes, but you could just as easily use a network stream which could be remoted or allow you to create a server that hands out business objects. The possibilities are limitless.



Serialize the Business Object

Private Sub SerializeMethod()

'-- Establish Locals

Dim loFile As New System.IO.FileStream("c:\serializedBO.bin", System.IO.FileMode.Create)

Dim loCustomers As New CustomersBO()




'-- Load some data into the business object

loCustomers.FillAll()




'-- Serialize the business object to the stream

loCustomers.SerializeToStream(loFile)




'-- Close the stream

loFile.Close()




'-- Close the BO

loCustomers.Dispose()

End Sub




De-serialize the Business Object

Private Sub DeserializeMethod()

'-- Establish Lcoals

Dim loFile As New System.IO.FileStream("c:\serializedBO.bin", System.IO.FileMode.Open)

Dim loCustomers As CustomersBO




'-- Deserialize the saved business object from a stream

loCustomers = CustomersBO.DeserializeBusinessObject(loFile)




'-- Close the stream

loFile.Close()

End Sub

John Frankewicz
John Frankewicz
StrataFrame Beginner (40 reputation)StrataFrame Beginner (40 reputation)StrataFrame Beginner (40 reputation)StrataFrame Beginner (40 reputation)StrataFrame Beginner (40 reputation)StrataFrame Beginner (40 reputation)StrataFrame Beginner (40 reputation)StrataFrame Beginner (40 reputation)StrataFrame Beginner (40 reputation)
Group: Forum Members
Posts: 36, Visits: 65
Our application requires that fields in the database, represented by the business object, be serialized remotely.

Could someone explain the process or point me to a link that explains how this process is done in your framework?

1. Do you have an option where the  serialized data is  stored?

2. Can it be hooked into the .net remoting?

3. How do you select what is serialized? I thought it was done after the object is dropped on the form?

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...




Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search