Bug 33571 - Mono crashes when marshalling fixed arrays
Summary: Mono crashes when marshalling fixed arrays
Alias: None
Product: Runtime
Classification: Mono
Component: Interop ()
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)

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:

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.