FirstName LastName | 15 Oct 13:41
Favicon

Marshaling DateTime type

What would be the best equivalent unmanaged type (linux and windows) to use if I want to marshal a DateTime in the managed world (.NET, mono)?
 
Thanks.

_______________________________________________
Mono-devel-list mailing list
Mono-devel-list <at> lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list
Robert Jordan | 15 Oct 14:20

Re: Marshaling DateTime type

FirstName LastName wrote:
> What would be the best equivalent unmanaged type (linux and windows)
> to use if I want to marshal a DateTime in the managed world (.NET,
> mono)?

You can't marshal DateTime directly because its internal representation
is different between runtimes *and* profiles. Use DateTime.Tick (an
int64) or a similar era-based representation.

Robert
Raja R Harinath | 15 Oct 15:46

Re: Marshaling DateTime type

Hi,

Robert Jordan <robertj <at> gmx.net> writes:

> FirstName LastName wrote:
>> What would be the best equivalent unmanaged type (linux and windows)
>> to use if I want to marshal a DateTime in the managed world (.NET,
>> mono)?
>
> You can't marshal DateTime directly because its internal representation
> is different between runtimes *and* profiles. Use DateTime.Tick (an
> int64) or a similar era-based representation.

But, IIRC, strangely enough, arrays of DateTimes should serialize fine.
So, you might be better of using a one-element DateTime array.

- Hari
Robert Jordan | 15 Oct 16:23

Re: Marshaling DateTime type

Raja R Harinath wrote:
> Hi,
> 
> Robert Jordan <robertj <at> gmx.net> writes:
> 
>> FirstName LastName wrote:
>>> What would be the best equivalent unmanaged type (linux and windows)
>>> to use if I want to marshal a DateTime in the managed world (.NET,
>>> mono)?
>> You can't marshal DateTime directly because its internal representation
>> is different between runtimes *and* profiles. Use DateTime.Tick (an
>> int64) or a similar era-based representation.
> 
> But, IIRC, strangely enough, arrays of DateTimes should serialize fine.
> So, you might be better of using a one-element DateTime array.

Look at DateTime's layout:

public struct DateTime
{
         private TimeSpan ticks;
#if NET_2_0
        	DateTimeKind kind;
#endif
}

Nasty things would happen if the unmanaged code is profile agnostic.

Robert
Raja R Harinath | 15 Oct 17:41

Re: Marshaling DateTime type

Hi,

Robert Jordan <robertj <at> gmx.net> writes:
> Raja R Harinath wrote:
>> Robert Jordan <robertj <at> gmx.net> writes:
>>> FirstName LastName wrote:
>>>> What would be the best equivalent unmanaged type (linux and windows)
>>>> to use if I want to marshal a DateTime in the managed world (.NET,
>>>> mono)?
>>> You can't marshal DateTime directly because its internal representation
>>> is different between runtimes *and* profiles. Use DateTime.Tick (an
>>> int64) or a similar era-based representation.
>> 
>> But, IIRC, strangely enough, arrays of DateTimes should serialize fine.
>> So, you might be better of using a one-element DateTime array.
>
> Look at DateTime's layout:
>
> public struct DateTime
> {
>          private TimeSpan ticks;
> #if NET_2_0
>         	DateTimeKind kind;
> #endif
> }
>
> Nasty things would happen if the unmanaged code is profile agnostic.

>From a quick examination of the source code in SVN trunk, my
understanding is that both the Binary and Soap serializers have special
cases for DateTime, which aren't dependent on the exact layout -- and
the serialization is profile-dependent.

(Of course, since I haven't actually tried it out, I can't guarantee
that it's fully interoperable with .NET.)

- Hari
Robert Jordan | 15 Oct 18:14

Re: Marshaling DateTime type

Hi,

Raja R Harinath wrote:
> Hi,
> 
> Robert Jordan <robertj <at> gmx.net> writes:
>> Raja R Harinath wrote:
>>> Robert Jordan <robertj <at> gmx.net> writes:
>>>> FirstName LastName wrote:
>>>>> What would be the best equivalent unmanaged type (linux and windows)
>>>>> to use if I want to marshal a DateTime in the managed world (.NET,
>>>>> mono)?
>>>> You can't marshal DateTime directly because its internal representation
>>>> is different between runtimes *and* profiles. Use DateTime.Tick (an
>>>> int64) or a similar era-based representation.
>>> But, IIRC, strangely enough, arrays of DateTimes should serialize fine.
>>> So, you might be better of using a one-element DateTime array.
>> Look at DateTime's layout:
>>
>> public struct DateTime
>> {
>>          private TimeSpan ticks;
>> #if NET_2_0
>>         	DateTimeKind kind;
>> #endif
>> }
>>
>> Nasty things would happen if the unmanaged code is profile agnostic.
> 
>>From a quick examination of the source code in SVN trunk, my
> understanding is that both the Binary and Soap serializers have special
> cases for DateTime, which aren't dependent on the exact layout -- and
> the serialization is profile-dependent.

Yes. Unfortunately, the special DateTime serialization is not used
in all cases (see the bug below).

Anyway, serialization doesn't apply to p/invoke. If I understood
correctly, the original poster was asking about managed/unmanaged
marshaling.

> 
> (Of course, since I haven't actually tried it out, I can't guarantee
> that it's fully interoperable with .NET.)

Here is the full story of DateTime serialization issues:

https://bugzilla.novell.com/show_bug.cgi?id=325067

Robert
FirstName LastName | 16 Oct 14:12
Favicon

Re: Marshaling DateTime type

Thanks everyone.  I think my best bet will be to use the Tick property.



> To: mono-devel-list <at> lists.ximian.com
> From: harinath <at> hurrynot.org
> Date: Wed, 15 Oct 2008 21:11:09 +0530
> Subject: Re: [Mono-dev] Marshaling DateTime type
>
> Hi,
>
> Robert Jordan <robertj <at> gmx.net> writes:
> > Raja R Harinath wrote:
> >> Robert Jordan <robertj <at> gmx.net> writes:
> >>> FirstName LastName wrote:
> >>>> What would be the best equivalent unmanaged type (linux and windows)
> >>>> to use if I want to marshal a DateTime in the managed world (.NET,
> >>>> mono)?
> >>> You can't marshal DateTime directly because its internal representation
> >>> is different between runtimes *and* profiles. Use DateTime.Tick (an
> >>> int64) or a similar era-based representation.
> >>
> >> But, IIRC, strangely enough, arrays of DateTimes should serialize fine.
> >> So, you might be better of using a one-element DateTime array.
> >
> > Look at DateTime's layout:
> >
> > public struct DateTime
> > {
> > private TimeSpan ticks;
> > #if NET_2_0
> > DateTimeKind kind;
> > #endif
> > }
> >
> > Nasty things would happen if the unmanaged code is profile agnostic.
>
> >From a quick examination of the source code in SVN trunk, my
> understanding is that both the Binary and Soap serializers have special
> cases for DateTime, which aren't dependent on the exact layout -- and
> the serialization is profile-dependent.
>
> (Of course, since I haven't actually tried it out, I can't guarantee
> that it's fully interoperable with .NET.)
>
> - Hari
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list <at> lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list

Get your information fix on your phone. With MSN Mobile you get regular news, sports and  finance updates. Try it today!
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list <at> lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Gmane