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 for Bug 23954 on
GitHub or Developer Community if you have new
information to add and do not yet see a matching new report.
If the latest results still closely match this report, you can use the
In special cases on GitHub you might also want the comments:
GitHub Markdown with public comments
SGen fails when collecting a class with LayoutKind.Explicit.
public long @signed;
public string Text;
public static void Main(string args)
var array = new ExplicitLayout;
for (int i = 0; i < array.Length; i++)
array[i] = new ExplicitLayout();
array[i].@signed = i;
Mono/Sgen will crash with an exception on the invoke of GC.Collect. Most likely it is trying to collect the Text string member which isn't a valid reference.
This is by design, the GC expects that fields that hold references contain valid values.
Ok, so I guess the major difference with .NET is that it throws a TypeLoadException at start up rather than throwing in the GC when it sees the bad reference.
The full MS exception message at program start is:
Could not load type 'TestExplictLayout.ExplicitLayout' from assembly 'ConsoleApplication2, Version=126.96.36.199, Culture=neutral, PublicKeyToken=null' because it contains an object field at offset 0 that is incorrectly aligned or overlapped by a non-object field.
We should probably do the same.
I guess at least the app gets a chance to catch the System.Exception and report some meaningful info to the user then - always useful!
Fixed in mono master 8d9f05ea9a943ff1a36bb0ef3dd0521853d3a489.
The fix has to be reverted as apparently too much real-life code depends on this.
You can enable the verifier to check for this.