Bug 30679 - Error: Compiler crashed with code: 1.
Summary: Error: Compiler crashed with code: 1.
Alias: None
Product: Compilers
Classification: Mono
Component: C# ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Marek Safar
Depends on:
Reported: 2015-06-02 12:46 UTC by Stephen Rawlins
Modified: 2015-06-05 10:56 UTC (History)
4 users (show)

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

Compiler Debug-level build diagnostics (2.86 MB, text/rtf)
2015-06-02 12:46 UTC, Stephen Rawlins

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 Stephen Rawlins 2015-06-02 12:46:19 UTC
Created attachment 11434 [details]
Compiler Debug-level build diagnostics

When I try to build, the compiler crashes.

I set my Diagnostic level to Debug and have attached the output from the build.
Comment 1 Sebastien Pouliot 2015-06-02 14:08:05 UTC
The compiler used by XI comes from the Mono version you have installed. Can you give us all* the versions of the software being used ?

* The easiest way to get exact version information is to use the "Xamarin Studio" menu, "About Xamarin Studio" item, "Show Details" button and copy/paste the version informations (you can use the "Copy Information" button).
Comment 2 Stephen Rawlins 2015-06-02 14:10:54 UTC
Thank you, Sebastien.
Here is my "About" Details:

=== Xamarin Studio ===

Version 5.9.2 (build 2)
Installation UUID: 69759d01-e512-4032-89db-884a8fdd22ee
	Mono 4.0.1 ((detached/ed1d3ec)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400010044

=== Apple Developer Tools ===

Xcode 6.3.2 (7718)
Build 6D2105

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/steverawlins/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.2   (API level 17)
		4.4   (API level 19)
		5.0   (API level 21)
Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Not Installed

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: e6ebd18
Branch: master
Build date: 2015-05-21 21:55:09-0400

=== Build Information ===

Release ID: 509020002
Git revision: 43735a4b905b571f69cf9428a3ea7b52aef55476
Build date: 2015-05-18 09:38:12-04
Xamarin addins: ab18ddff45f507ed74f36c2b65df9aee22e28a56

=== Operating System ===

Mac OS X 10.10.3
Darwin Steves-MacBook-Pro.local 14.3.0 Darwin Kernel Version 14.3.0
    Mon Mar 23 11:59:05 PDT 2015
    root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
Comment 3 Marek Safar 2015-06-02 14:50:32 UTC
I am not sure I can do much about it at this point. It fails dure to "System.IO.FileLoadException: I/O Error" which is general I/O error. Can this be reliable reproducible out of your machine.
Comment 4 Stephen Rawlins 2015-06-02 16:02:43 UTC
I reproduced the "Compiler crashed with code: 1" when creating a new solution and adding-in the existing debug projects one-by-one.
Comment 5 Marek Safar 2015-06-03 06:06:42 UTC
Could you share the project with me?
Comment 6 Stephen Rawlins 2015-06-03 12:33:27 UTC
I'm not sure yet if I'll be able to share the entire project with you, but judging from the Build Diagnostics, the Mono.CSharp compiler crashes because it cannot import an assembly (see snippet below from the attached build log)

Why would a failed import cause the compiler to crash?

Environment variables being passed to the tool:
		Unhandled Exception:
		Mono.CSharp.InternalErrorException: Failed to import assembly `iFactr.Data, Version=,
Comment 7 Stephen Rawlins 2015-06-04 09:47:23 UTC
I believe I found the cause.

The solution consists of a unit-test project "UT" and the target (to be tested) project "P"

P is a signed DLL and it contains an internal class.

UT wishes to test that internal class, but cannot because it's internal.  To gain access to the internal, we used Microsoft's "Friendly Assembly" attribute, having P explicitly grant access to UT as if they were both in the same assembly:

So, in P's AssemblyInfo.cs:

[assembly: InternalsVisibleTo("UT, PublicKeyToken=<xxxxxxxx>")]

The above seems to cause the compiler crash.  When I comment it out, no crash.
Comment 8 Marek Safar 2015-06-04 10:47:58 UTC
Could you give me complete [assembly: InternalsVisibleTo("UT, PublicKeyToken=<xxxxxxxx>")] so I can try to reproduce the issue
Comment 9 Stephen Rawlins 2015-06-04 14:55:50 UTC
I cannot give you all the materials, but I can explain how to reproduce the error in a small test case:

Create a solution with a project containing an internal class

Next, create an NUnit test project 

        // NOTE: since constructor method is internal you must
        //   cheat C#'s rules by using assembly: InternalsVisibleTo() this test assembly.
        //   That way, the test can invoke the otherwise internal class.
        public void TestTheInternalClass()
            var myObj = new MyProject.NetworkResource.ResourceRequest();

Here is the class being tested:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace MyProject.NetworkResource
    public class ResourceRequest

        private string _uri = null;
        public int Timeout;
        public string Uri
            get { return _uri; }
            internal set
                if (string.IsNullOrEmpty(value))
                    throw new ArgumentNullException("value");
                _uri = value;

// here is the internal constructor
        internal ResourceRequest( string uri)
            Uri = uri;

// other methods ...   not relevant
        public ResourceResponse GetResponse(int timeoutMilliseconds )
			Timeout = timeoutMilliseconds;


In order to test the constructor, you must put make a "Friendly" assembly directive, so in the MyProject's  Properties/AssemblyInfo.cs:

[assembly: InternalsVisibleTo("UnitTests.Data.MT, PublicKeyToken=<xxxx>")]

where is "xxxx" is the key you signed MyProject with.
Comment 10 Stephen Rawlins 2015-06-04 15:04:24 UTC
For signed assemblies you need the assembly's public key (that's the "xxxx" in my code sample, that's the Public Key).

To acquire the public key of a signed assembly you will need the "sn.exe" tool that ships with Visual Studio. 

// From the "Visual Studio Command Prompt": 
// sn -Tp c:\MyExample\SomeLibrary.Test.dll
Comment 11 Marek Safar 2015-06-05 10:56:30 UTC
Fixed in master