Bug 30679

Summary: Error: Compiler crashed with code: 1.
Product: [Mono] Compilers Reporter: Stephen Rawlins <srawlins>
Component: C#Assignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: mono-bugs+monodevelop, mono-bugs+monotouch, mono-bugs+mono, sebastien
Priority: ---    
Version: unspecified   
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: Compiler Debug-level build diagnostics

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
Runtime:
	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: 5.1.2.1 (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: 8.10.1.64 (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
Marek,
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=3.5.2.42,
Comment 7 Stephen Rawlins 2015-06-04 09:47:23 UTC
Marek,
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.
        [Test]
        public void TestTheInternalClass()
        {
            var myObj = new MyProject.NetworkResource.ResourceRequest();
            Assert.IsNotNull(myObj);
        }



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