Notice (2018-05-24): bugzilla.xamarin.com is now in
Please join us on
Visual Studio Developer Community and in the
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
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.
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 .
Worked around on CppSharp: https://github.com/mono/CppSharp/commit/6623161200e039c70254fec8371241e7370a49ca
Does it also fail if the StructLayout and the FieldOffset attributes are removed ? They are not really needed.
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?".
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.
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.
It has been almost a year and this obvious bug has received no attention whatsoever. When is it going to be fixed?
Fixed in master 20b49905f26fac15338aa2862b119de9026cb4f7.
So it was a bug after all. :) Thanks for the fix.