SerializeToStream function
 
Home My Account Forum Try It! Buy It!
About Contact Us Site Map
StrataFrame Forum
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      



SerializeToStream functionExpand / Collapse
Author
Message
Posted 11/23/2005 3:43:14 PM
StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: Forum Members
Last Login: 05/25/2007 3:34:57 PM
Posts: 235, Visits: 309
Using this code:
MemoryStream myStream = new MemoryStream();
boAllUsers1.NewRow();
boAllUsers1.SerializeToStream(myStream);
myStream.Position = 0;
BOLibrary.boAllUsers allUsers = (BOLibrary.boAllUsers)BusinessLayer.DeserializeBusinessObject(myStream);

1) {"Type 'BOLibrary.boAllUsers' in Assembly 'BOLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' is not marked as serializable."}

Is this something that we are supposed to have to address manually for each BO or should the code generator mark them all as [Serializable]?

2) The SerializeToStream method should set the Position to 0 before returning. Otherwise you get an "End of Stream reached unexpectedly" exception on the DeserializeBusinessObject call.

3) After addressing 1 and 2 the following exception is thrown:
{"The constructor to deserialize an object of type 'BOLibrary.boAllUsers' was not found."}

Post #98
Posted 11/23/2005 4:17:43 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: 2 days ago @ 9:53:39 AM
Posts: 2,654, Visits: 1,869
Yes, the [Serializable()] attribute must be added to the business objects before they can be serialized... we modified the StrataFrame Business Object template to have the attribute as well as the constructor needed to deserialize the business object. So, your current business objects will need to be modified, but any business objects you create here on out will automatically support it. So, easiest way to fix your current business objects is to add a new one using the template and copy the code out that is needed for the serialization (the [Serializable()] attribute on the class definition and the "Constructors" region in the main code file.

NOTE: the constructors have been pulled from the designer file and added to the main code file. Many users were worried that they could not modify any of the code within the designer file. (You can modify anything within the "Component Implementation" region and your changes won't be overriden.)



www.bungie.net
Post #100
Posted 11/23/2005 4:21:52 PM


StrataFrame Developer

StrataFrame Developer

Group: StrataFrame Developers
Last Login: 2 days ago @ 9:53:39 AM
Posts: 2,654, Visits: 1,869
On the resetting the position of the stream to 0, we're not going to modify any portion of the stream after we write the business object to it, because it might not be the only object on the stream (you can write several business objects to the same stream, and setting the position to 0 after each one would cause them to overwrite each other). Additionally, you cannot modify the position manually on all streams, (the System.Security.Cryptography.CryptoStream and System.Net.NetworkStream come to mind) and trying to set it would throw an exception on these streams. It's better to let the developer manage his own stream position than modify it without his knowledge.


www.bungie.net
Post #102
Posted 11/23/2005 4:38:22 PM
StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: Forum Members
Last Login: 05/25/2007 3:34:57 PM
Posts: 235, Visits: 309
Thank you. Everything seems to be working as you described.

I have a residual problem with this little sample that I am working on:

The table schema looks like this:
new DataColumn("ID", typeof(System.String)),


In my code:
boAllUsers1.NewRow();
boAllUsers1.ID = "FRED";

throws the following exception:
{"Input string was not in a correct format.Couldn't store in ID Column. Expected type is Int32."}

and if you use the visualizer to look at the underlying DataTable, it shows a -1 in the ID column.

All of the generated code seems to know that this column is a string column but the datatable thinks it's an int.

This has me stumped.
Post #105
Posted 11/23/2005 4:42:52 PM
StrataFrame User

StrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame UserStrataFrame User

Group: Forum Members
Last Login: 05/25/2007 3:34:57 PM
Posts: 235, Visits: 309
On the position resetting issue, your logic is inescapable. It also answers my other question about where to create a new stream.

Thank you.
Post #107
« Prev Topic | Next Topic »


Reading This TopicExpand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Ben Chase, Trent L. Taylor, Steve L. Taylor

PermissionsExpand / Collapse

All times are GMT -6:00, Time now is 12:20am

Powered By InstantForum.NET v4.1.4 © 2008
Execution: 0.078. 9 queries. Compression Enabled.
Site Map - Home - My Account - Forum - About Us - Contact Us - Try It - Buy It

Microsoft, Visual Studio, and the Visual Studio logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries.