Bug 20349 - Crash (in iOS simulator) when instantiating a class with a static readonly reference to an empty struct
Summary: Crash (in iOS simulator) when instantiating a class with a static readonly re...
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 7.2.3
Hardware: PC Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Zoltan Varga
Depends on:
Reported: 2014-06-04 14:54 UTC by mscoder610
Modified: 2014-06-05 14:06 UTC (History)
3 users (show)

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

Test Case for crash (Xamarin iOS project) (3.46 KB, application/x-zip-compressed)
2014-06-04 14:56 UTC, mscoder610
Full stack trace / crash details (5.67 KB, text/plain)
2014-06-04 14:56 UTC, mscoder610

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 Developer Community or GitHub 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 mscoder610 2014-06-04 14:54:03 UTC
Using Xamarin.iOS on a Mac, I'm running into a crash while running my app on the simulator. I was able to come up with a small test case (attached) - basically this:

public struct MyStruct
public class MyClass
    public static readonly MyStruct StructInstance = new MyStruct();

Running a program that tries to create an instance of MyClass, using the Debug|iPhoneSimulator or Release|iPhoneSimulator configurations will crash with the following error:

* Assertion at ../../../../../mono/mono/mini/method-to-ir.c:10339, condition `addr' not met

The full stack trace is attached.
Adding a property to the struct causes the error go away, as does removing the explicit StructLayout(LayoutKind.Sequential) attribute.
The app runs fine on an actual iPad device (Release|iPhone configuration).

The error looks somewhat similar to Xamarin Bug 18963:
Comment 1 mscoder610 2014-06-04 14:56:18 UTC
Created attachment 6980 [details]
Test Case for crash (Xamarin iOS project)
Comment 2 mscoder610 2014-06-04 14:56:42 UTC
Created attachment 6981 [details]
Full stack trace / crash details
Comment 3 Sadik Ali 2014-06-05 04:06:31 UTC
I have checked this issue and able to reproduce it.  I have created a new project and added the code from 'Appdelegate.cs' page given in comment 1 Attachment 'Test Case for crash (Xamarin iOS project)' in new created project. I added the breakpoint to debug this application and it crashed when it initiating a class with a static reference.

Screencast for same : http://screencast.com/t/FpVE2mwko

Supplement Info :
Build Log : https://gist.github.com/saurabh360/bf40403b3e68a5d0eae6
Application Output Log :  https://gist.github.com/saurabh360/cd66c30f4b1e6a6f71fe
IDE Log : https://gist.github.com/saurabh360/a94a851b947b2250df0f

Environment Info : 
=== Xamarin Studio ===

Version 5.0 (build 878)
Installation UUID: 1151d3d9-29c1-4339-b53c-a54856b47901
	Mono 3.4.0 ((no/c3fc3ba)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 304000204

=== Xamarin.Android ===

Version: 4.12.4 (Enterprise Edition)
Android SDK: /Users/shruti/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		3.2   (API level 13)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
Java SDK: /usr
java version "1.7.0_55"
Java(TM) SE Runtime Environment (build 1.7.0_55-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.55-b03, mixed mode)

=== Apple Developer Tools ===

Xcode 5.1 (5084)
Build 5B130a

=== Xamarin.iOS ===

Version: (Enterprise Edition)
Hash: fc6f56b
Build date: 2014-05-19 19:10:29-0400

=== Xamarin.Mac ===

Xamarin.Mac: Not Installed

=== Build Information ===

Release ID: 500000878
Git revision: bcd66920d963483e7d638a2339c4022fe035b529
Build date: 2014-05-27 17:36:26-04
Xamarin addins: da9064ce55b0fa90930a7c437a4cc1ae0e5c778c

=== Operating System ===

Mac OS X 10.9.2
Darwin Shrutis-Mac-mini.local 13.1.0 Darwin Kernel Version 13.1.0
    Thu Jan 16 19:40:37 PST 2014
    root:xnu-2422.90.20~2/RELEASE_X86_64 x86_64
Comment 4 Sebastien Pouliot 2014-06-05 11:53:56 UTC
Looks like a JIT/runtime issue. Zoltan can you have a look ?
Comment 5 Zoltan Varga 2014-06-05 13:06:19 UTC
Fixed in mono master 2aa7af58636bc7c5499d4c150c64f51bf73b30c3.
Comment 6 mscoder610 2014-06-05 14:06:13 UTC
Very quick turnaround for this one, thanks.

Any idea what version of Xamarin.iOS the fix will make it into?