473,785 Members | 2,987 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

.NET Serialization Quest

Hi All,

I have a question concerning serialization in .NET.

If I serialize an object to a database and then I change the object in code
(i.e. add a property, rename a property, delete a property) will my object
deserialize correctly?

Will it throw an exception - or will it deserialize whatever it can?

If serialization is going to throw an error, is there a way to do a "best
effort" deserialization or handle changed objects?

Thanks!
Nov 14 '06 #1
5 1313

Spam Catcher wrote:
Hi All,

I have a question concerning serialization in .NET.

If I serialize an object to a database and then I change the object in code
(i.e. add a property, rename a property, delete a property) will my object
deserialize correctly?

Will it throw an exception - or will it deserialize whatever it can?

If serialization is going to throw an error, is there a way to do a "best
effort" deserialization or handle changed objects?

Thanks!
I have another question: how are you serializing your objects to the
database? I just started work on a similar problem and I haven't even
gotten the objects to the database yet. If I can get that far, I'll let
you know how well they come back out of the database.

Nov 14 '06 #2

Spam Catcher wrote:
Hi All,

I have a question concerning serialization in .NET.

If I serialize an object to a database and then I change the object in code
(i.e. add a property, rename a property, delete a property) will my object
deserialize correctly?

Will it throw an exception - or will it deserialize whatever it can?

If serialization is going to throw an error, is there a way to do a "best
effort" deserialization or handle changed objects?

Thanks!
I have another question: how are you serializing your objects to the
database? I just started work on a similar problem and I haven't even
gotten the objects to the database yet. If I can get that far, I'll let
you know how well they come back out of the database.

Nov 14 '06 #3
lo*********@gma il.com wrote in news:1163520931 .928255.279730
@i42g2000cwa.go oglegroups.com:
I have another question: how are you serializing your objects to the
database? I just started work on a similar problem and I haven't even
gotten the objects to the database yet. If I can get that far, I'll
let
you know how well they come back out of the database.
Here's my code:

Public Shared Function Serialize(ByVal instance As Object) As String
Dim _Serializer As New SoapFormatter

Using _MS As New MemoryStream
Try
_Serializer.Ser ialize(_MS, instance)

Return System.Text.Enc oding.ASCII.Get String(_MS.ToAr ray)
Catch ex As Exception
Return ""
End Try
End Using

End Function

Public Shared Function Deserialize(ByV al XML As String) As Object
Dim _Serializer As New SoapFormatter

Using _MS As New MemoryStream
(System.Text.En coding.ASCII.Ge tBytes(XML))
Try
Return _Serializer.Des erialize(_MS)
Catch ex As Exception
Return Nothing
End Try
End Using
End Function
Nov 14 '06 #4
That depends on how you do it. I'm assuming you're serializing to XML
using an IXmlSerializabl e implementation. In that case, you're pretty
much in charge of the serialization and therefore the behavior under
fringe cases.

If this is the case, the story goes something like this:

1) You have your object. You create an XmlSerializer that'll spit out
either a file or a stream containing your XML upon request. You can
either tie the stream to blob access or turn the stream in to a string
and write it parametrically.

2) When you get your object back, you get the same, either a string or
a stream. You create an XmlSerializer and pass it your data as a
stream.

3) It'll call your null constructor then the implemented ReadXml()
method. Whatever you've chosen to write in the method will work as
written.

The implication of this is that you can make your ReadXml() method as
robust to change as you want. If the version 1.0 object has members A
and B and version 2.0 adds C, everything *can* work out if ReadXml() is
overridden correctly and C is nullable or defaultable.

As far as properties and such, you're on your own. Serialization
couldn't care less about anything outside the IXmlSerializabl e
implementation.
Stephan

Spam Catcher wrote:
Hi All,

I have a question concerning serialization in .NET.

If I serialize an object to a database and then I change the object in code
(i.e. add a property, rename a property, delete a property) will my object
deserialize correctly?

Will it throw an exception - or will it deserialize whatever it can?

If serialization is going to throw an error, is there a way to do a "best
effort" deserialization or handle changed objects?

Thanks!
Nov 14 '06 #5
First, you need to separate xml-serialization and
binary/SOAP-serialization; they work differently.
When adding fields/properties:
For binary, you can look at [OptionalField], or provide your own "best
efforst" implementation via ISerializable without too much trouble.

For xml, you can look at [DefaultValue], which has the effect of making
a property optional. You could also implement IXmlSerializabl e, but
IIRC it is a pig (providing the schema, mainly).

When deleting: you tell me. A simple test app should take about 3
minutes to write...

Marc

Nov 14 '06 #6

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

Similar topics

1
2408
by: Trent | last post by:
Hello, I was wondering if anyone here could help with a Quest Central issue. I have two different hosts listed in Quest Central. Each host has a database on it, but the databases have the *same* name. I can add the database to the first host OK. But when I try to add the second host's database, I get an error saying "Database name already exists." Is there a way around this problem? Why does it matter if databases
3
1727
by: Robert Stearns | last post by:
Apparently due to an intellectual property suit by CA, Quest Central for DB2 has gone away. They can/will not sell any license extensions. In a project I am doing, we make extensive use of quest due to its ease of use and speed. If you know of a product with similar capabilities, please let me know. My license is running out this month. Inexpensive is very important since we're a dining room table startup.
3
3177
by: Aaron Clamage | last post by:
Hi, I'm not sure that if this is the right forum, but any help would be greatly appreciated. I am porting some java serialization code to c# and I can't figure out the correct way to do it. It seems that either I can use default serialization or implement ISerializable. Is there any way to do both (e.g. extend the default serialization). In other words, I want to be able to implement my custom serialization code but call the...
3
2459
by: Alexander | last post by:
When i store rule on PC with .NET.SP1 i cant restore them from PC without SP1. An i get this Error: System.Runtime.Serialization.SerializationException: Possible Version mismatch. Type System.Collections.Comparer has 1 members, number of members deserialized is 0. at System.Runtime.Serialization.Formatters.Binary.ReadObjectInfo.GetMemberTypes(String
5
972
by: Spam Catcher | last post by:
Hi All, I have a question concerning serialization in .NET. If I serialize an object to a database and then I change the object in code (i.e. add a property, rename a property, delete a property) will my object deserialize correctly? Will it throw an exception - or will it deserialize whatever it can?
4
11413
by: mijalko | last post by:
Hi, I have inherited my class from System.Drawing.Printing.PrintDocument and I wish to serialize this object using XmlSerializer. And I get exception "There was an error reflecting type ...". If I look at innerException it says: "Cannot serialize member 'System.ComponentModel.Component.Site' of type 'System.ComponentModel.ISite'. OK it is problem to serialize all data so I'll implement my Serialization. I implemented ISerializable...
1
11104
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject : IPersistable;
2
5568
by: mkvenkit.vc | last post by:
Hello, I hope this is the right place to post a question on Boost. If not, please let me know where I can post this message and I will do so. I am having a strange problem with std::string as I am trying to read from a binary archive using Boost serialization. I am new to this, and it is possible that I have not understood the usage. In the code below, the string "faultblock" seems to be causing the problem. The code crashes in the ia...
4
1556
by: bj7lewis | last post by:
I am currently C++/Win32/MFC & C# programmer using VS.NET 2002 and jumped into VS.NET 2003 but that was a waste so I skipped VS.NET 2005 cause buying VS.NET 2003. Now after checking out VS.NET 2008 Beta2 I think VS.NET 2008 is worth the upgrade. But I want to hold off(five+ years depending on features) on more further upgrades OSs & ISEs cause of too many releases - too soon - too much money.... So now going to VS.NET 2008 I want to setup a...
0
9645
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
10327
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10092
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
8973
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
7499
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
5381
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4053
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
3
2879
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.