Bug 16310 - structure layout does not match .NET
Summary: structure layout does not match .NET
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: Interop ()
Version: 3.2.x
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Zoltan Varga
URL:
Depends on:
Blocks:
 
Reported: 2013-11-18 01:00 UTC by Salil Agarwal
Modified: 2014-06-05 18:05 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Comment 1 Zoltan Varga 2013-11-18 09:50:15 UTC
Mono aligns struct sizes and offsets to 8 for performance reasons, this can cause differences versus .net.
Comment 2 Salil Agarwal 2013-11-19 01:20:00 UTC
Thanks for the response, I can understand the reason but we have a situation where a C based library (both on linux and Windows) provides a decode stream of bytes and we just type cast it required structure type in C#. It works in .Net and also with gmcs built binary when run on Windows. Only with mono on linux it fails.

Can we have some option in mono to execute binary on linux with same layout as Windows. Even if it is not best performing it is not a big issue with us currently.
Comment 3 Salil Agarwal 2013-11-27 02:47:16 UTC
Hi,

 Any comments on this one?

Regards,
Salil
Comment 4 Zoltan Varga 2013-11-27 03:32:45 UTC
As a workaround, try inlining the inner structure members into the outer structure.
Comment 5 Rodrigo Kumpera 2013-12-10 17:21:31 UTC
As workaround, use struct layout custom attributes to control size, alignment and offsets.

This is not a bug in mono, it's a platform difference to with portable code must care for.
Comment 6 Zoltan Varga 2013-12-10 17:38:15 UTC
This is actually a bug in mono.
Comment 7 Rodrigo Kumpera 2013-12-16 15:01:52 UTC
Where's the bug?
Comment 8 Zoltan Varga 2014-06-05 18:05:37 UTC
This seems to work with mono 3.4.0.