Bug 24873 - The LinkAssemblies task failed unexpectedly
Summary: The LinkAssemblies task failed unexpectedly
Status: RESOLVED UPSTREAM
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild ()
Version: 4.20.0
Hardware: PC Windows
: Normal normal
Target Milestone: ---
Assignee: Radek Doulik
URL:
Depends on:
Blocks:
 
Reported: 2014-11-27 02:38 UTC by Roman Cervenak
Modified: 2017-09-14 19:27 UTC (History)
4 users (show)

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

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:
Status:
RESOLVED UPSTREAM

Description Roman Cervenak 2014-11-27 02:38:37 UTC
When trying to "publish android app" (release configuration, linking set to SDK assemblies only) in xamarin 3.8.150.0, I get:

The "LinkAssemblies" task failed unexpectedly.
System.NullReferenceException: Object reference not set to an instance of an object.
   at Mono.Cecil.Mixin.GetNestedType(TypeDefinition self, String name)
   at Mono.Cecil.TypeParser.TryGetDefinition(ModuleDefinition module, Type type_info, TypeReference& type)
   at Mono.Cecil.TypeParser.GetTypeReference(ModuleDefinition module, Type type_info)
   at Mono.Cecil.TypeParser.ParseType(ModuleDefinition module, String fullname)
   at Mono.Cecil.SignatureReader.ReadTypeReference()
   at Mono.Cecil.SignatureReader.ReadCustomAttributeElementValue(TypeReference type)
   at Mono.Cecil.SignatureReader.ReadCustomAttributeElement(TypeReference type)
   at Mono.Cecil.SignatureReader.ReadCustomAttributeFixedArgument(TypeReference type)
   at Mono.Cecil.SignatureReader.ReadCustomAttributeConstructorArguments(CustomAttribute attribute, Collection`1 parameters)
   at Mono.Cecil.MetadataReader.ReadCustomAttributeSignature(CustomAttribute attribute)
   at Mono.Cecil.CustomAttribute.<Resolve>m__1(CustomAttribute attribute, MetadataReader reader)
   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TItem item, Func`3 read)
   at Mono.Cecil.CustomAttribute.Resolve()
   at Mono.Cecil.CustomAttribute.get_HasConstructorArguments()
   at Mono.Linker.Steps.MarkStep.MarkCustomAttributeArguments(CustomAttribute ca)
   at Mono.Linker.Steps.MarkStep.MarkCustomAttribute(CustomAttribute ca)
   at Mono.Linker.Steps.MarkStep.MarkCustomAttributes(ICustomAttributeProvider provider)
   at Mono.Linker.Steps.MarkStep.ProcessMethod(MethodDefinition method)
   at Mono.Linker.Steps.MarkStep.ProcessQueue()
   at Mono.Linker.Steps.MarkStep.Process()
   at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
   at Mono.Linker.Pipeline.Process(LinkContext context)
   at MonoDroid.Tuner.Linker.Process(LinkerOptions options, LinkContext& context)
   at Xamarin.Android.Tasks.LinkAssemblies.Execute()
   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
   at Microsoft.Build.BackEnd.TaskBuilder.<ExecuteInstantiatedTask>d__20.MoveNext()

My Visual Studio info:

Microsoft Visual Studio Professional 2013
Version 12.0.31101.00 Update 4
Microsoft .NET Framework
Version 4.5.50938

Installed Version: Professional

Team Explorer for Visual Studio 2013   06177-004-0446025-02206
Microsoft Team Explorer for Visual Studio 2013

Visual Basic 2013   06177-004-0446025-02206
Microsoft Visual Basic 2013

Visual C# 2013   06177-004-0446025-02206
Microsoft Visual C# 2013

Visual C++ 2013   06177-004-0446025-02206
Microsoft Visual C++ 2013

Visual F# 2013   06177-004-0446025-02206
Microsoft Visual F# 2013

Visual Studio 2013 Code Analysis Spell Checker   06177-004-0446025-02206
Microsoft® Visual Studio® 2013 Code Analysis Spell Checker

Portions of International CorrectSpell™ spelling correction system © 1993 by Lernout & Hauspie Speech Products N.V. All rights reserved.

The American Heritage® Dictionary of the English Language, Third Edition Copyright © 1992 Houghton Mifflin Company. Electronic version licensed from Lernout & Hauspie Speech Products N.V. All rights reserved.

Application Insights Tools for Visual Studio Package   1.0
Application Insights Tools for Visual Studio

ASP.NET and Web Tools   12.4.51016.0
Microsoft Web Developer Tools contains the following components:
Support for creating and opening ASP.NET web projects
Browser Link: A communication channel between Visual Studio and browsers
Editor extensions for HTML, CSS, and JavaScript
Page Inspector: Inspection tool for ASP.NET web projects
Scaffolding: A framework for building and running code generators
Server Explorer extensions for Microsoft Azure Websites
Web publishing: Extensions for publishing ASP.NET web projects to hosting providers, on-premises servers, or Microsoft Azure

ASP.NET Web Frameworks and Tools 2012.2   4.1.21001.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.2.21010.0
For additional information, visit http://www.asp.net/

Common Azure Tools   1.3
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Microsoft Azure HDInsight HQL Service   1.0.0000.0
Language service for Hive query

Microsoft Azure HDInsight Tools for Visual Studio   1.0.0000.0
An integrated development environment for HDInsight application development.

Microsoft Azure Mobile Services Tools   1.3
Microsoft Azure Mobile Services Tools

Microsoft Azure Tools   2.5
Microsoft Azure Tools for Microsoft Visual Studio 2013 - v2.5.21104.1601

Microsoft Azure Tools   2.4
Microsoft Azure Tools for Microsoft Visual Studio 2013 - v2.4.20730.1601

NuGet Package Manager   2.8.50926.663
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

PowerShell Tools   1.3
Provides file classification services using PowerShell

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   12.0.41012.0
Microsoft SQL Server Data Tools

Windows Azure Tools   2.3
Windows Azure Tools for Microsoft Visual Studio 2013 - v2.3.20320.1602

Windows Phone 8.1 SDK Integration   1.0
This package integrates the tools for the Windows Phone 8.1 SDK into the menus and controls of Visual Studio.

Xamarin   3.8.150.0 (10cfd178d55287f09c85f5a1e604dfe20889a40f)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   4.20.0.28 (ba9bbbdd44cfdc4bf485e8885bd2ad24fba525f7)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   8.4.0.0 (840a925103a0bf4a856507f13d5eaee3c1579c2f)
Visual Studio extension to enable development for Xamarin.iOS.

Git Extensions
Git Extensions is a graphical interface for Git
For more information about Git Extensions, see the Git Extensions website at
http://code.google.com/p/gitextensions/
Copyright © 2012 Henk Westhuis
Comment 1 Akhilesh kumar 2015-01-02 06:46:36 UTC
I have tried to reproduce this issue at my end but unable to reproduce. I am successfully able to Publish Android Application with same builds.

I have followed below steps:

Pre-requisite: Open Command Prompt as Administrator.
1. Move to Keytool location for ex in 64 bit machine its "C:\Program Files (x86)\Java\jdk1.6.0_31\bin"
and run command keytool -genkeypair -alias certificatekey -keyalg RSA -validity 7 -keystore keystore.jks and 
Note: "Keystore.jks " is name of keystore to be generated, If it already exist than use some other name like xyz.keystore or delete it from bin.
2. Enter all fields and note all the details which you have entered like Alise, Password and Key password.
3. Create Android application.
4. Run the application in Release mode.
5. Click on Project->Package Android Application.
6. Enter the path of keystore which you have created in step1. for ex C:\Program Files (x86)\Java\jdk1.6.0_31\bin\keystore.jks
5. Enter alias, password and Key password.
6. Click Forward button.
7. Enter Target directory at select destination.
8. Click Create.

Screencast: http://screencast.com/t/adR7f4sEwzZ

Could you please try it again? If you are still facing this issue then please attach IDE log(Via Help-> Xamarin Zip Log) and application output.

Environment info:
Microsoft Visual Studio Professional 2013
Version 12.0.31101.00 Update 4
Microsoft .NET Framework
Version 4.5.51641

Installed Version: Professional

LightSwitch for Visual Studio 2013   06177-004-0444002-02320
Microsoft LightSwitch for Visual Studio 2013

Team Explorer for Visual Studio 2013   06177-004-0444002-02320
Microsoft Team Explorer for Visual Studio 2013

Visual Basic 2013   06177-004-0444002-02320
Microsoft Visual Basic 2013

Visual C# 2013   06177-004-0444002-02320
Microsoft Visual C# 2013

Visual C++ 2013   06177-004-0444002-02320
Microsoft Visual C++ 2013

Visual F# 2013   06177-004-0444002-02320
Microsoft Visual F# 2013

Visual Studio 2013 Code Analysis Spell Checker   06177-004-0444002-02320
Microsoft® Visual Studio® 2013 Code Analysis Spell Checker

Portions of International CorrectSpell™ spelling correction system © 1993 by Lernout & Hauspie Speech Products N.V. All rights reserved.

The American Heritage® Dictionary of the English Language, Third Edition Copyright © 1992 Houghton Mifflin Company. Electronic version licensed from Lernout & Hauspie Speech Products N.V. All rights reserved.

Windows Phone SDK 8.0 - ENU   06177-004-0444002-02320
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package   1.0
Application Insights Tools for Visual Studio

ASP.NET and Web Tools   12.4.51016.0
Microsoft Web Developer Tools contains the following components:
Support for creating and opening ASP.NET web projects
Browser Link: A communication channel between Visual Studio and browsers
Editor extensions for HTML, CSS, and JavaScript
Page Inspector: Inspection tool for ASP.NET web projects
Scaffolding: A framework for building and running code generators
Server Explorer extensions for Microsoft Azure Websites
Web publishing: Extensions for publishing ASP.NET web projects to hosting providers, on-premises servers, or Microsoft Azure

ASP.NET Web Frameworks and Tools 2012.2   4.1.21001.0
For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563

ASP.NET Web Frameworks and Tools 2013   5.2.21010.0
For additional information, visit http://www.asp.net/

Common Azure Tools   1.3
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Microsoft Azure Mobile Services Tools   1.3
Microsoft Azure Mobile Services Tools

NuGet Package Manager   2.8.50926.663
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

Office Developer Tools for Visual Studio 2013 ENU   12.0.30626
Microsoft Office Developer Tools for Visual Studio 2013 ENU

PowerShell Tools   1.3
Provides file classification services using PowerShell

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

SQL Server Data Tools   12.0.41012.0
Microsoft SQL Server Data Tools

Windows Phone 8.1 SDK Integration   1.0
This package integrates the tools for the Windows Phone 8.1 SDK into the menus and controls of Visual Studio.

Workflow Manager Tools 1.0   1.0
This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin   3.8.150.0 (10cfd178d55287f09c85f5a1e604dfe20889a40f)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   4.20.0.28 (ba9bbbdd44cfdc4bf485e8885bd2ad24fba525f7)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   8.4.0.0 (840a925103a0bf4a856507f13d5eaee3c1579c2f)
Visual Studio extension to enable development for Xamarin.iOS.
Comment 2 Roman Cervenak 2015-01-12 10:04:22 UTC
My mistake, I forgot one very important information: linking is failing while using LogicNP CryptoObfuscator for .NET in this project. I am aware that not all features are supported with Xamarin and our obfuscation configuration using only basic ones. Also, before Xamarin 3.8. everything worked just fine with obfuscation enabled (no changes here, just upgrade to 3.8. broke building process on linking step). I tried to contact LogicNP support with this, but I doubt they will know much about Xamarin custom linking process.
Comment 7 Roman Cervenak 2015-02-06 03:39:57 UTC
I was able to find workaround (more like hack) to this problem. 
1. I downloaded Mono.Cecil source code from github
2. Found class Mono.Cecil.Mixin and method GetNestedType in it
3. Added checks for null like this:

 if (self == null || !self.HasNestedTypes) ... 
 if (nested_types != null) ...
 if (nested_type != null && nested_type.TypeFullName() == fullname) ...

4. Changed assembly name in project properties to Xamarin.Android.Cecil and Xamarin.Android.Cecil.Mdb

5. Changed InternalsVisibleTo in Assembly info as needed (Xamarin.Android.Cecil.Mdb instead of Mono.Cecil.Mdb)

6. Build in release net_4_0
7. Replace assemblies in c:\Program Files (x86)\MSBuild\Xamarin\Android\ with built ones

Result: linking obfuscated project is now working. 
However, I found that calls to System.Net.Http.HttpClient failing - there is no exception, but HTTP requests are simply not getting out. I excluded System and System.Net.Http from linking : <AndroidLinkSkip>System%3bSystem.Net.Http</AndroidLinkSkip>

And now everything is working OK so far.
I know this is nasty and totally unsupported (since there is probably a good reason why Xamarin team included their own version of Mono.Cecil) and I hope this will be resolved by Xamarin team so I could revert this hack on my side. But for now it works.
Comment 8 Radek Doulik 2015-02-13 07:58:57 UTC
I have tried to reproduce the bug, using BugDemo.zip from https://xamarin.desk.com/agent/case/116974, but it built OK. (I noticed I have newer jdk 1.7, but that shouldn't matter in case of the linker)

Does the bug still happen?

Jon, could you ask guys from https://xamarin.desk.com/agent/case/122594 for a testcase we can use to reproduce the issue?
Comment 10 Roman Cervenak 2015-07-27 03:48:46 UTC
Hey guys, update on this issue. I consulted it with author of Mono.Cecil and we managed to reproduce the case and it has been fixed in Mono.Cecil, see https://github.com/jbevain/cecil/issues/233 . So please update your clone Xamarin.Android.Cecil eventually to reflect this fix.
Comment 11 Jon Douglas [MSFT] 2017-09-14 19:27:31 UTC
Seeing that this issue is closed in github:

https://github.com/jbevain/cecil/commit/3723f62e1a68e27338490483dea387c02110049f

It seems this commit has made the Mono dependency as well:

https://github.com/mono/cecil/blob/c0eb983dac62519d3ae93a689312076aacecb723/Mono.Cecil/TypeParser.cs#L376-L382

Thus marking this RESOLVED UPSTREAM