Bug 22892 - Linking fails with "Error executing task LinkAssemblies: System.NullReferenceException" at Mono.Cecil.Mixin.GetNestedType
Summary: Linking fails with "Error executing task LinkAssemblies: System.NullReference...
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: General (show other bugs)
Version: 4.16.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Jonathan Pryor
URL:
Depends on:
Blocks:
 
Reported: 2014-09-11 18:57 UTC by Kent Green [MSFT]
Modified: 2014-09-24 11:19 UTC (History)
7 users (show)

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


Attachments
Logfiles from the error (524.45 KB, application/zip)
2014-09-11 18:57 UTC, Kent Green [MSFT]
Details
Minimized test case (20.42 KB, application/zip)
2014-09-11 19:35 UTC, Brendan Zagaeski (Xamarin Support)
Details
Diagnostic build output (356.40 KB, text/plain)
2014-09-11 19:54 UTC, Brendan Zagaeski (Xamarin Support)
Details

Description Kent Green [MSFT] 2014-09-11 18:57:46 UTC
Created attachment 8006 [details]
Logfiles from the error

Overview:
Linker error MT2001: Object reference not set to an instance of an object at Mono.Cecil.Mixin.GetNestedType.

Steps to reproduce:
Will be described in a private comment with the test case demonstrating the issue is from a customer's app.

From priority case:
https://xamarin.desk.com/agent/case/88323

gist of full stack trace:
https://gist.github.com/brendanzagaeski/fb83c90cf12272d4905c

Build information:
=== Xamarin Studio ===

Version 5.4 (build 216)
Installation UUID: 8ef63a7c-1b18-40de-a334-7f78777fcb55
Runtime:
	Mono 3.8.0 ((no/45d0ba1)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 308000009

=== Apple Developer Tools ===

Xcode 5.1.1 (5085)
Build 5B1008

=== Xamarin.iOS ===

Version: 8.0.0.9 (Business Edition)
Hash: 436246d
Branch: 
Build date: 2014-09-10 00:04:26-0400

=== Xamarin.Mac ===

Version: 1.10.0.10 (Business Edition)

=== Xamarin.Android ===

Version: 4.16.0 (Business Edition)
Android SDK: /Users/kentgreen/Library/Developer/Xamarin/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)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.4   (API level 19)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)

=== Build Information ===

Release ID: 504000216
Git revision: bf73535e350da9a84b6990c72149b84467757c52
Build date: 2014-09-09 15:40:19-04
Xamarin addins: cb699c7d52f13def4e9746f8086e9f24ef6d894f

=== Operating System ===

Mac OS X 10.9.4
Darwin Kents-MacBook-Pro.local 13.3.0 Darwin Kernel Version 13.3.0
    Tue Jun  3 21:27:35 PDT 2014
    root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64
Comment 1 Kent Green [MSFT] 2014-09-11 19:08:06 UTC
I was asked to file a duplicate bug report for the same issue occurring in iOS, which is available here: https://bugzilla.xamarin.com/show_bug.cgi?id=22893
Comment 2 Brendan Zagaeski (Xamarin Support) 2014-09-11 19:35:25 UTC
Created attachment 8009 [details]
Minimized test case

## Steps to reproduce

Attempt to build either the Android app or the iPhone app with the linker mode set to "Link SDK assemblies only".


## Result

Top of the stack trace:
 
> error MT2001: Could not link assemblies. Reason: Object reference not set to an instance of an object
> --- inner exception
> System.NullReferenceException: Object reference not set to an instance of an object
>   at Mono.Cecil.Mixin.GetNestedType (Mono.Cecil.TypeDefinition self, System.String name) [0x00000] in <filename unknown>:0 
>   at Mono.Cecil.TypeParser.TryGetDefinition (Mono.Cecil.ModuleDefinition module, Mono.Cecil.Type type_info, Mono.Cecil.TypeReference& type) [0x00000] in <filename unknown>:0 
>   at Mono.Cecil.TypeParser.GetTypeReference (Mono.Cecil.ModuleDefinition module, Mono.Cecil.Type type_info) [0x00000] in <filename unknown>:0 
>   at Mono.Cecil.TypeParser.ParseType (Mono.Cecil.ModuleDefinition module, System.String fullname) [0x00000] in <filename unknown>:0 
>   at Mono.Cecil.SignatureReader.ReadTypeReference () [0x00000] in <filename unknown>:0 


## Additional information

The 2 app projects are just the default template projects. The PCL project contains just the following code:

public async Task<T> GetAsync<T>(string url) where T : new()
{
    return await Task.Factory.StartNew(async () =>
    {
        var client = new HttpClient();
        var response = await client.GetStringAsync(url);
        return (T)new object();
    }).Unwrap();
}


Commenting out the `var response = await client.GetStringAsync(url);` line stops the problem.
Comment 3 Brendan Zagaeski (Xamarin Support) 2014-09-11 19:54:34 UTC
Created attachment 8010 [details]
Diagnostic build output

One small correction for Android: the error message doesn't refer to MT2001, but the stack trace is still the same.

> Error executing task LinkAssemblies: System.NullReferenceException: Object reference not set to an instance of an object
>   at Mono.Cecil.Mixin.GetNestedType (Mono.Cecil.TypeDefinition self, System.String name) [0x00000] in <filename unknown>:0 
>   at Mono.Cecil.TypeParser.TryGetDefinition (Mono.Cecil.ModuleDefinition module, Mono.Cecil.Type type_info, Mono.Cecil.TypeReference& type) [0x00000] in <filename unknown>:0 
>   at Mono.Cecil.TypeParser.GetTypeReference (Mono.Cecil.ModuleDefinition module, Mono.Cecil.Type type_info) [0x00000] in <filename unknown>:0 
>   at Mono.Cecil.TypeParser.ParseType (Mono.Cecil.ModuleDefinition module, System.String fullname) [0x00000] in <filename unknown>:0 
>   at Mono.Cecil.SignatureReader.ReadTypeReference () [0x00000] in <filename unknown>:0
Comment 4 Brendan Zagaeski (Xamarin Support) 2014-09-11 21:38:41 UTC
It looks like this is actually a Mono compiler or Cecil bug [1], so we can most likely close this as a duplicate of the iOS bug.
[1] https://bugzilla.xamarin.com/show_bug.cgi?id=22893#c6
Comment 5 Prashant manu 2014-09-12 02:32:45 UTC
As per comment 4, updating status as duplicate.

*** This bug has been marked as a duplicate of bug 22893 ***
Comment 6 Sebastien Pouliot 2014-09-12 07:59:26 UTC
@Prashant you're not working on the bug so please don't close it.

Different products needs different bug reports for many reasons, including the fact that QA won't be able to verity the fix on both product independently.
Comment 7 Sebastien Pouliot 2014-09-12 11:15:35 UTC
Marek backported the fix to 3.8 (and 3.10) in mono-3.8.0-branch
db71bc145b655e57e8f5529b23da37ccb933b4c2

QA: this needs to be verify using the current XA stable and the mono 3.8.x version that
includes the above commit.
Comment 9 Mohit Kheterpal 2014-09-24 11:19:31 UTC
I have checked this Issue and now I am able to build attached application successfully with latest Mono. This is the build output for the same: https://gist.github.com/saurabh360/2c6d9b3a727a397b689a

X.S 5.4 (Build 241)
Git revision: d7682de02218437de17ceeaad94c6ec63239b925
Mono 3.8.0-13
X.iOS 8.0.0.63

I was able to reproduce this Issue with Mono 3.8.0-9.

Note You need to log in before you can comment on or make changes to this bug.