Bug 33571 - Mono crashes when marshalling fixed arrays
Summary: Mono crashes when marshalling fixed arrays
Alias: None
Product: Runtime
Classification: Mono
Component: Interop (show other bugs)
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Bugzilla
Depends on:
Reported: 2015-09-02 12:16 UTC by Dimitar Dobrev
Modified: 2016-08-25 19:06 UTC (History)
4 users (show)

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


Description Dimitar Dobrev 2015-09-02 12:16:10 UTC
When marshalling a struct for a platform invocation, Mono crashes if the struct has a fixed array. Sample code and a complete stack trace can be found at https://gist.github.com/tritao/7e62c71ffe57d6bc326e .
Comment 1 João Matos 2015-09-02 12:35:48 UTC
Worked around on CppSharp: https://github.com/mono/CppSharp/commit/6623161200e039c70254fec8371241e7370a49ca
Comment 2 Zoltan Varga 2015-09-04 00:59:43 UTC
Does it also fail if the StructLayout and the FieldOffset attributes are removed ? They are not really needed.
Comment 3 Dimitar Dobrev 2015-09-04 06:55:29 UTC
It's obvious that this piece was cut down from a much larger one to make the test case as small as possible. It's just as obvious the larger one needs those attributes because nobody would add them just for fun. How should one feel about spending time to reduce the test case in order not to get the regular "please add a smaller test case otherwise we're going to do nothing about this", just to get "why is this test case so small?".
Comment 4 Zoltan Varga 2015-09-09 17:27:19 UTC
So the problem here is that that structure is not fully defined, it has holes in it, so the runtime doesn't know how to pass/receive it from native code, since the native ABI requires all struct members to be defined/consecutive.
Comment 5 Dimitar Dobrev 2015-09-10 03:57:35 UTC
The structure is actually correctly defined, that is, the bug is not in the example. First, it works with MS .NET. Second, it has an array of 3 elements x 4 bytes per int = 12 bytes, exactly the size specified in the layout.
Comment 6 Dimitar Dobrev 2016-08-24 16:27:48 UTC
It has been almost a year and this obvious bug has received no attention whatsoever. When is it going to be fixed?
Comment 7 Zoltan Varga 2016-08-25 18:45:18 UTC
Fixed in master 20b49905f26fac15338aa2862b119de9026cb4f7.
Comment 8 Dimitar Dobrev 2016-08-25 19:06:29 UTC
So it was a bug after all. :) Thanks for the fix.

Notice (2018-05-21): bugzilla.xamarin.com will be switching to read-only mode on Thursday, 2018-05-25 22:00 UTC.

Please join us on Visual Studio Developer Community and GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs and copy them to the new locations as needed for follow-up. The See Also field on each Bugzilla bug will be updated with a link to its new location when applicable.

After Bugzilla is read-only, if you have new information to add for a bug that does not yet have a matching issue on Developer Community or GitHub, you can create a follow-up issue in the new location. Copy and paste the title and description from this bug, and then add your new details. You can get a pre-formatted version of the title and description here:

In special cases you might also want the comments:

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.

Note You need to log in before you can comment on or make changes to this bug.