Xamarin-android: App builds hang when executing task LinkAssemblies if linking enabled

Created on 28 Oct 2019  路  20Comments  路  Source: xamarin/xamarin-android

Steps to Reproduce

  1. Build app with AndroidLinkMode=Full or AndroidLinkMode=SdkOnly

Expected Behavior

App builds successfully.

Actual Behavior

Build hangs.

It always hangs at the same point - while executing Task "LinkAssemblies" after logging:

Type System.Reflection.Emit.PointerType has no fields to preserve

Example log excerpt: https://gist.github.com/frankbuckley/8b729ccfa89b0d01970557d5e83dd604

I can reproduce with multiple projects building on Windows and on OSX.

An apparently identical report is on Stackoverflow: https://stackoverflow.com/questions/58552286/xamarin-android-build-just-hangs-when-linker-is-enabled

The issue seems to have been introduced since mid-September.

Version Information

Microsoft Visual Studio Enterprise 2019
Version 16.3.6
VisualStudio.16.Release/16.3.6+29418.71
Microsoft .NET Framework
Version 4.8.03752

Installed Version: Enterprise

Visual C++ 2019   00435-60000-00000-AA197
Microsoft Visual C++ 2019

ADL Tools Service Provider   1.0
This package contains services used by Data Lake tools

ASP.NET and Web Tools 2019   16.3.286.43615
ASP.NET and Web Tools 2019

ASP.NET Web Frameworks and Tools 2019   16.3.286.43615
For additional information, visit https://www.asp.net/

Azure App Service Tools v3.0.0   16.3.286.43615
Azure App Service Tools v3.0.0

Azure Data Lake Node   1.0
This package contains the Data Lake integration nodes for Server Explorer.

Azure Data Lake Tools for Visual Studio   2.4.2000.0
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools   16.3.286.43615
Azure Functions and Web Jobs Tools

Azure Logic Apps Tools for Visual Studio   1.0
Add-in for the Azure Resource Group project to support the Logic App Designer and template creation.

Azure Stream Analytics Tools for Visual Studio   2.4.2000.0
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools   3.3.1-beta3-19461-02+2fd12c210e22f7d6245805c60340f6a34af6875b
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

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

Cookiecutter   16.3.19252.1
Provides tools for finding, instantiating and customizing templates in cookiecutter format.

EditorConfig Language Service   1.17.260
Language service for .editorconfig files.

EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs.

Extensibility Message Bus   1.2.0 (d16-2@8b56e20)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Fabric.DiagnosticEvents   1.0
Fabric Diagnostic Events

File Icons   2.7
Adds icons for files that are not recognized by Solution Explorer

GitHub.VisualStudio   2.10.8.8132
A Visual Studio Extension that brings the GitHub Flow into Visual Studio.

IntelliCode Extension   1.0
IntelliCode Visual Studio Extension Detailed Info

Markdown Editor   1.12.236
A full featured Markdown editor with live preview and syntax highlighting. Supports GitHub flavored Markdown.

Microsoft Azure HDInsight Azure Node   2.4.2000.0
HDInsight Node under Azure Node

Microsoft Azure Hive Query Language Service   2.4.2000.0
Language service for Hive query

Microsoft Azure Service Fabric Tools for Visual Studio   16.0
Microsoft Azure Service Fabric Tools for Visual Studio

Microsoft Azure Stream Analytics Language Service   2.4.2000.0
Language service for Azure Stream Analytics

Microsoft Azure Stream Analytics Node   1.0
Azure Stream Analytics Node under Azure Node

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 0x10 - v2.9.20816.1

Microsoft Continuous Delivery Tools for Visual Studio   0.4
Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager   2.0.83+gbc8a4b23ec
Install client-side libraries easily to any web project

Microsoft MI-Based Debugger   1.0
Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards   1.0
Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers   1.1
Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package   1.0
Microsoft Visual Studio VC Package

Mono Debugging for Visual Studio   16.3.7 (9d260c5)
Support for debugging Mono processes with Visual Studio.

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

Open Command Line   2.4.226
2.4.226

PowerShell Pro Tools for Visual Studio   1.0
A set of tools for developing and debugging PowerShell scripts and modules in Visual Studio.

Productivity Power Tools 2017/2019   16.0
Installs the individual extensions of Productivity Power Tools 2017/2019

Project File Tools   1.0.1
Provides Intellisense and other tooling for XML based project files such as .csproj and .vbproj files.

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

Python   16.3.19252.1
Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Python - Conda support   16.3.19252.1
Conda support for Python projects.

Python - Django support   16.3.19252.1
Provides templates and integration for the Django web framework.

Python - IronPython support   16.3.19252.1
Provides templates and integration for IronPython-based projects.

Python - Profiling support   16.3.19252.1
Profiling support for Python projects.

Redgate SQL Prompt   9.5.20.11737
Write, format, and refactor SQL effortlessly

Snapshot Debugging Extension   1.0
Snapshot Debugging Visual Studio Extension Detailed Info

SQL Server Data Tools   16.0.61908.27190
Microsoft SQL Server Data Tools

Test Adapter for Boost.Test   1.0
Enables Visual Studio's testing tools with unit tests written for Boost.Test.  The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test   1.0
Enables Visual Studio's testing tools with unit tests written for Google Test.  The use terms and Third Party Notices are available in the extension installation directory.

ToolWindowHostedEditor   1.0
Hosting json editor into a tool window

TypeScript Tools   16.0.10821.2002
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   3.3.1-beta3-19461-02+2fd12c210e22f7d6245805c60340f6a34af6875b
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual C++ for Cross Platform Mobile Development (Android)   16.0.29230.54
Visual C++ for Cross Platform Mobile Development (Android)

Visual F# Tools 10.4 for F# 4.6   16.3.0-beta.19455.1+0422ff293bb2cc722fe5021b85ef50378a9af823
Microsoft Visual F# Tools 10.4 for F# 4.6

Visual Studio Code Debug Adapter Host Package   1.0
Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for CMake   1.0
Visual Studio Tools for CMake

Visual Studio Tools for CMake   1.0
Visual Studio Tools for CMake

Visual Studio Tools for Containers   1.0
Visual Studio Tools for Containers

Visual Studio Tools for Kubernetes   1.0
Visual Studio Tools for Kubernetes

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Xamarin   16.3.0.277 (d16-3@c0fcab7)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   16.3.0.246 (remotes/origin/d16-3@bd2f86892)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   16.3.565 (27e9746)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   10.0.3.0 (d16-3/4d45b41)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: mono/mono/2019-06@5608fe0abb3
    Java.Interop: xamarin/java.interop/d16-3@5836f58
    LibZipSharp: grendello/LibZipSharp/d16-3@71f4a94
    LibZip: nih-at/libzip/rel-1-5-1@b95cf3fd
    ProGuard: xamarin/proguard/master@905836d
    SQLite: xamarin/sqlite/3.27.1@8212a2d
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-3@cb41333


Xamarin.iOS and Xamarin.Mac SDK   13.4.0.2 (e37549b)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.
App+Library Build

Most helpful comment

Release status update

A new Release version has now been published on macOS that includes the fix for this item.

Fix included in Xamarin.Android 10.2.0.100.

Fix included on macOS in Visual Studio 2019 for Mac version 8.5. To get the new version that includes the fix, check for the latest updates on the Stable updater channel.

(Fix also included on Windows in Visual Studio 2019 version 16.5 and higher. To get the new version that includes the fix, check for the latest updates or install the latest version from https://visualstudio.microsoft.com/downloads/.)


Neither App Center nor the Microsoft-hosted agents for Azure Pipeline have yet been updated to include this new version. I will continue to keep an eye on those services and update this item when a version is available that includes the fix.

All 20 comments

I encountered this as well, and the single difference that I made was to remove explicit support for Nullable reference types (<Nullable>enable</Nullable>) from my project file.

For example, in my project file with three configuration/platform PropertyGroups:

@@ -29,7 +29,6 @@
     <WarningLevel>4</WarningLevel>
     <NoWarn>VSTHRD200</NoWarn>
     <LangVersion>8.0</LangVersion>
-    <Nullable>enable</Nullable>
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
     <DebugType>pdbonly</DebugType>
@@ -40,7 +39,6 @@
     <WarningLevel>4</WarningLevel>
     <NoWarn>VSTHRD200</NoWarn>
     <LangVersion>8.0</LangVersion>
-    <Nullable>enable</Nullable>
   </PropertyGroup>
   <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'VLU1|AnyCPU'">
     <DebugSymbols>true</DebugSymbols>
@@ -52,7 +50,6 @@
     <ErrorReport>prompt</ErrorReport>
     <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
     <LangVersion>8.0</LangVersion>
-    <Nullable>enable</Nullable>
   </PropertyGroup>
   <ItemGroup>
     <Reference Include="Microsoft.CSharp" />

Thanks! Not in my app project, but <Nullable>enable</Nullable> had crept into a referenced class library.

Removing it fixes the build with linking enabled.

Wow, thanks so much, I'm the Mick Byrne behind the Stack Overflow post referenced by the OP. Your recommended fix worked (though weirdly, for me, the <Nullable>enable</Nullable> was only in the Debug configuration where linking was disabled and already removed in my Preview and Release configurations; guess it just needs to be removed in all configurations).

@frankbuckley @mickbyrne @thzinc does this problem happen with a File->New Project? If so, can you attach it? Thanks!

I tried just adding this to a template, but it seemed to work for me 馃槥 :

  <PropertyGroup>
    ...
    <LangVersion>8.0</LangVersion>
    <Nullable>enable</Nullable>
  </PropertyGroup>

I tried using VS 16.3.9 and VS 16.4 Preview.

No, this didn't happen when we started a fresh project. The issue seems to be triggered by certain code patterns that confuse the linker, in particular when we implemented marked classes as implementing certain interfaces (from 3rd party packages).

For us we managed to trace it all back to a couple of specific commits:

  • The Android.Animation.IAnimatorUpdateListener <- I'd say this is your best bet to reproduce.
  • A buch of interfaces from Naxam's bindings of the MapBox Android SDK, specifically IOnMapReadyCallback, Style.IOnStyleLoaded, IOnMapClickListener on the MapView class.

Good luck!

Thank you for the repro sample. I am able to reproduce the problem locally with it.

So far it looks like the linker issue is related to processing System.Void System.Runtime.CompilerServices.NullableAttribute::.ctor(System.Byte) (constructor) method.

@jonathanpeppers I'm experiencing this by creating a new blank xamarin.forms app on VS 16.4.3 and installing this package:
https://www.nuget.org/packages/Shiny.Locations/1.0.0.572-beta
After installing this package on a brand new Xamarin.Forms application a trying to build in release with linker = SdkOnly the build enters in an infinite loop.

@ederbond I have an internal build that will be 16.5 Preview 3, and the issue seems fixed there.

@brendanzagaeski goes through and comments when a fix is in a public release. Hopefully it won't be too much longer?

Release status update

A new Preview version has now been published that includes the fix for this item. The fix is not yet included in a Release version. I will update this item again when a Release version is available that includes the fix.

Fix included in Xamarin.Android 10.2.0.84.

Fix included on Windows in Visual Studio 2019 version 16.5 Preview 2. To try the Preview version that includes the fix, check for the latest updates in Visual Studio Preview.

Fix included on macOS in Visual Studio 2019 for Mac version 8.5 Preview 1. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel.

@brendanzagaeski @jonathanpeppers please, also post a comment here when this fix is published on AppCenter.ms build machines images.

Any infos when this version will be stable?

-- Eddy

Release status update

A new Release version has now been published on Windows that includes the fix for this item. The fix is not yet published in a Release version on macOS. I will update this item again when a Release version is available on macOS that includes the fix. I will also keep an eye on AppCenter and update this item when a version is available that includes the fix.

Fix included in Xamarin.Android 10.2.0.100.

Fix included on Windows in Visual Studio 2019 version 16.5. To get the new version that includes the fix, check for the latest updates or install the latest version from https://visualstudio.microsoft.com/downloads/.

(Fix also included on macOS in Visual Studio 2019 for Mac version 8.5 Preview 1 and higher. To try the Preview version that includes the fix, check for the latest updates on the Preview updater channel.)

Hey there, thanks for the update. Will Azure Devops VS 2019 build hosts get updated at the same time as App Center?

Release status update

A new Release version has now been published on macOS that includes the fix for this item.

Fix included in Xamarin.Android 10.2.0.100.

Fix included on macOS in Visual Studio 2019 for Mac version 8.5. To get the new version that includes the fix, check for the latest updates on the Stable updater channel.

(Fix also included on Windows in Visual Studio 2019 version 16.5 and higher. To get the new version that includes the fix, check for the latest updates or install the latest version from https://visualstudio.microsoft.com/downloads/.)


Neither App Center nor the Microsoft-hosted agents for Azure Pipeline have yet been updated to include this new version. I will continue to keep an eye on those services and update this item when a version is available that includes the fix.

Release status update

The windows-latest Microsoft-hosted Azure VM agents have now been updated to include Visual Studio 2019 version 16.5, which has the fix for this item.

I will continue to monitor for the corresponding updates for the macOS Microsoft-hosted Azure VM agents and App Center.

Release status update

The build agents for App Center have now been updated to include Xamarin.Android 10.2, which has the fix for this item.

The last set of images that are not yet updated are the macOS Microsoft-hosted Azure VM agents. I will continue to monitor for the corresponding update on those agents.

Hi,

Today I've started to have issues with Linker.

Repro steps: Create a fresh project and add Prism.Core library to Android project

Happens on both latest VS4Mac Stable and Preview.

Target "_LinkAssembliesShrink" in file "/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets":
  Building target "_LinkAssembliesShrink" completely.
  Output file "obj/Release/link.flag" does not exist.
  Task "CreateProperty" skipped, due to false condition; ( '$(AndroidLinkTool)' != '' ) was evaluated as ( '' != '' ).
  Task "MakeDir" skipped, due to false condition; ( '$(AndroidLinkTool)' != '' ) was evaluated as ( '' != '' ).
  Using "LinkAssemblies" task from assembly "/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Build.Tasks.dll".
  Task "LinkAssemblies"
    Processing resource linker descriptor: mscorlib.xml
    Processing resource linker descriptor: Mono.Android.xml
    Processing embedded resource linker descriptor: mscorlib.xml
    Duplicate preserve in descriptor mscorlib.xml from Xamarin.Android.Build.Tasks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null of System.AppDomain (Nothing).  Duplicate uses (Fields)
    Duplicate preserve in descriptor mscorlib.xml from Xamarin.Android.Build.Tasks, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null of System.AppDomainSetup (Fields).  Duplicate uses (Fields)
    Added method: Xamarin.Forms.Button Xamarin.Forms.Platform.Android.IButtonLayoutRenderer::get_Element() to type: Xamarin.Forms.Platform.Android.AppCompat.ButtonRenderer scope: Xamarin.Forms.Platform.Android.dll
    Type Mono.ValueTuple has no fields to preserve
    Type System.Reflection.Assembly has no fields to preserve
    Type System.Reflection.Emit.ByRefType has no fields to preserve
    Type System.Reflection.Emit.PointerType has no fields to preserve

edit: I use C# 7.3 to build with Nullable reference types disabled

@dominikprzywara, thanks for the info! It sounds like you're seeing something a bit different from this issue (#3852). When you get a chance, if you could submit a new issue and attach the diagnostic MSBuild output from your failing build so the team can take a look, that would be perfect. Thanks in advance!

Release status update

The macOS-10.14 and macOS-latest Microsoft-hosted agents for Azure Pipeline have now been updated to include Xamarin.Android 10.2, which has the fix for this item (#3852).

Was this page helpful?
0 / 5 - 0 ratings