PC Review


Reply
Thread Tools Rate Thread

Custom DateTime serialization

 
 
Zachary Turner
Guest
Posts: n/a
 
      11th Aug 2006
Hello,

I have a situation where I would like to perform custom serialization
and deserialization of an existing .NET framework object (specifically,
System.DateTime). Is there a common paradigm here, for how I can
override the default behavior of DateTime serialization and provide my
own? I want to use this custom serialized DateTime in many places, and
don't want to provide custom serialization routines for every single
object that uses one of these DateTimes, it just seems easier to just
apply it directly to the DateTime object so that everywhere I use it,
it automatically picks up my new method.

The reason I'm doing this is because I'm doing .NET remoting with a 2.0
server and clients which might be either 1.1 or 2.0. I want the
serialization to behave correctly no matter what version the client is.

 
Reply With Quote
 
 
 
 
Michael Klingensmith
Guest
Posts: n/a
 
      12th Aug 2006
I've already done a few tests on serializing between the two versions .net
(1.1 and 2.0) with good results (didn't test DateTime though). What exactly
is the difference between the two versions ?

Mike
http://www.seeknsnatch.com

"Zachary Turner" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> I have a situation where I would like to perform custom serialization
> and deserialization of an existing .NET framework object (specifically,
> System.DateTime). Is there a common paradigm here, for how I can
> override the default behavior of DateTime serialization and provide my
> own? I want to use this custom serialized DateTime in many places, and
> don't want to provide custom serialization routines for every single
> object that uses one of these DateTimes, it just seems easier to just
> apply it directly to the DateTime object so that everywhere I use it,
> it automatically picks up my new method.
>
> The reason I'm doing this is because I'm doing .NET remoting with a 2.0
> server and clients which might be either 1.1 or 2.0. I want the
> serialization to behave correctly no matter what version the client is.
>



 
Reply With Quote
 
Zachary Turner
Guest
Posts: n/a
 
      18th Aug 2006
The difference is in 2.0 DateTimes are serialized with one extra field.
A 2 bit (i think) value specifying whether the following serialized
time is Utc or Local time. When .NET 1.1 tries to deserialize this, it
obviously fails and throws an exception. As far as I know many objects
work successfully when serializing across versions, but DateTime seems
to be one of the exceptions to the rule.

Is there any way to override the default deserialization behavior for
the entire type?

Michael Klingensmith wrote:
> I've already done a few tests on serializing between the two versions .net
> (1.1 and 2.0) with good results (didn't test DateTime though). What exactly
> is the difference between the two versions ?
>
> Mike
> http://www.seeknsnatch.com
>
> "Zachary Turner" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Hello,
> >
> > I have a situation where I would like to perform custom serialization
> > and deserialization of an existing .NET framework object (specifically,
> > System.DateTime). Is there a common paradigm here, for how I can
> > override the default behavior of DateTime serialization and provide my
> > own? I want to use this custom serialized DateTime in many places, and
> > don't want to provide custom serialization routines for every single
> > object that uses one of these DateTimes, it just seems easier to just
> > apply it directly to the DateTime object so that everywhere I use it,
> > it automatically picks up my new method.
> >
> > The reason I'm doing this is because I'm doing .NET remoting with a 2.0
> > server and clients which might be either 1.1 or 2.0. I want the
> > serialization to behave correctly no matter what version the client is.
> >


 
Reply With Quote
 
Dave Sexton
Guest
Posts: n/a
 
      18th Aug 2006
Hi Zachary,

Take a look at the following interfaces:

System.Runtime.Serialization.ISurrogateSelector
System.Runtime.Serialization.ISerializationSurrogate

They allow you to provide serialization and deserialization logic that replaces the default logic for any given Type.

SurrogateSelector class on MSDN (has an example):
http://msdn2.microsoft.com/en-us/lib...eselector.aspx

--
Dave Sexton

"Zachary Turner" <(E-Mail Removed)> wrote in message news:(E-Mail Removed)...
> The difference is in 2.0 DateTimes are serialized with one extra field.
> A 2 bit (i think) value specifying whether the following serialized
> time is Utc or Local time. When .NET 1.1 tries to deserialize this, it
> obviously fails and throws an exception. As far as I know many objects
> work successfully when serializing across versions, but DateTime seems
> to be one of the exceptions to the rule.
>
> Is there any way to override the default deserialization behavior for
> the entire type?
>
> Michael Klingensmith wrote:
>> I've already done a few tests on serializing between the two versions .net
>> (1.1 and 2.0) with good results (didn't test DateTime though). What exactly
>> is the difference between the two versions ?
>>
>> Mike
>> http://www.seeknsnatch.com
>>
>> "Zachary Turner" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > Hello,
>> >
>> > I have a situation where I would like to perform custom serialization
>> > and deserialization of an existing .NET framework object (specifically,
>> > System.DateTime). Is there a common paradigm here, for how I can
>> > override the default behavior of DateTime serialization and provide my
>> > own? I want to use this custom serialized DateTime in many places, and
>> > don't want to provide custom serialization routines for every single
>> > object that uses one of these DateTimes, it just seems easier to just
>> > apply it directly to the DateTime object so that everywhere I use it,
>> > it automatically picks up my new method.
>> >
>> > The reason I'm doing this is because I'm doing .NET remoting with a 2.0
>> > server and clients which might be either 1.1 or 2.0. I want the
>> > serialization to behave correctly no matter what version the client is.
>> >

>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DateTime wrapper serialization Jarlaxle Microsoft C# .NET 1 11th Mar 2008 01:00 AM
Patch for DateTime serialization =?Utf-8?B?QnJpYW4=?= Microsoft Dot NET Framework 1 13th Aug 2007 10:58 PM
2.0 to 1.1 Version Tolerant DateTime Serialization Mork Microsoft Dot NET Framework 0 17th Jan 2006 10:25 PM
.NET Webservice - DateTime XML serialization wrong? (please help) RobertD Microsoft ADO .NET 0 4th Oct 2004 10:22 AM
DateTime being changed during Xml Serialization of a DataSet using WSE 1.0 Chris Langston Microsoft ADO .NET 5 18th Jun 2004 08:28 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:57 AM.