[Mono-dev] 'sizeof' returns different results between .NET and Mono/Linux: a bug?

Robert Jordan robertj at gmx.net
Sun Jan 7 10:55:13 EST 2007


Lionel Cuir wrote:
> Trying to understand what was wrong, I discovered that a given struct has not 
> the same size for .NET and for Mono / Linux, even when playing with the Pack 
> args. That seems very surprising... and I would it a bug of Mono on Linux. Any 
> advice on this?

DateTime has different sizes between the runtimes and even between
runtime versions, so your code is doomed to break even on MS.NET
sooner or later.

Since DateTime is not under your control, you can't influence
its marshaling behavior. Hence you must either use binary serialization
or some surrogate representation of DateTime (DateTime.Ticks,
for example). This applies to all types that are not under your
control.

About your own types: you have to apply explicit packing to them,
because packing differs between platforms. Usually this doesn't
matter, because unmanaged libs have the same packing difference,
but since you're exchanging data over the wire, it becomes important.

Robert




More information about the Mono-devel-list mailing list