Bug 59822 - Building an Android solution in Release mode that references a net standard project with a Microsoft.Identity reference results in a linker error.
Summary: Building an Android solution in Release mode that references a net standard p...
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: MSBuild (show other bugs)
Version: 8.0 (15.4)
Hardware: Macintosh Mac OS
: High blocker
Target Milestone: 15.5
Assignee: Radek Doulik
URL:
Depends on:
Blocks:
 
Reported: 2017-09-28 15:55 UTC by Dave Thomas
Modified: 2017-11-01 21:08 UTC (History)
8 users (show)

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


Attachments

Description Dave Thomas 2017-09-28 15:55:07 UTC
Building an Android solution in Release mode that references a net standard project with a Microsoft.Identity reference results in a linker error.

mono 5.4.0.199
Xamarin.Android
Version: 8.0.0.21

A GitHub repo is available here which shows the issue: https://github.com/7sharp9/androidTest

steps:
git clone https://github.com/7sharp9/androidTest
cd androidTest
dotnet restore netstandardLib
msbuild androidTest /p:Configuration="Release"

This results in a build error:

"/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj" (default target) (1) ->
(_LinkAssembliesShrink target) ->
  /Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018: The "LinkAssemblies" task failed unexpectedly. [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018: System.NullReferenceException: Object reference not set to an instance of an object [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Cecil.MetadataBuilder.AddLocalConstants (Mono.Cecil.Cil.ScopeDebugInformation scope) [0x00011] in <4dd2191b08944f9681af2c1a582b646f>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Cecil.MetadataBuilder.AddLocalScope (Mono.Cecil.Cil.MethodDebugInformation method_info, Mono.Cecil.Cil.ScopeDebugInformation scope) [0x000b9] in <4dd2191b08944f9681af2c1a582b646f>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Cecil.MetadataBuilder.AddMethodDebugInformation (Mono.Cecil.Cil.MethodDebugInformation method_info) [0x0001f] in <4dd2191b08944f9681af2c1a582b646f>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Cecil.Cil.PortablePdbWriter.Write (Mono.Cecil.Cil.MethodDebugInformation info) [0x00006] in <4dd2191b08944f9681af2c1a582b646f>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Cecil.Cil.CodeWriter.WriteResolvedMethodBody (Mono.Cecil.MethodDefinition method) [0x000f1] in <4dd2191b08944f9681af2c1a582b646f>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Cecil.Cil.CodeWriter.WriteMethodBody (Mono.Cecil.MethodDefinition method) [0x0002b] in <4dd2191b08944f9681af2c1a582b646f>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Cecil.MetadataBuilder.AddMethod (Mono.Cecil.MethodDefinition method) [0x00013] in <4dd2191b08944f9681af2c1a582b646f>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Cecil.MetadataBuilder.AddMethods (Mono.Cecil.TypeDefinition type) [0x00013] in <4dd2191b08944f9681af2c1a582b646f>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Cecil.MetadataBuilder.AddType (Mono.Cecil.TypeDefinition type) [0x000a2] in <4dd2191b08944f9681af2c1a582b646f>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Cecil.MetadataBuilder.AddNestedTypes (Mono.Cecil.TypeDefinition type) [0x0001c] in <4dd2191b08944f9681af2c1a582b646f>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Cecil.MetadataBuilder.AddType (Mono.Cecil.TypeDefinition type) [0x000ed] in <4dd2191b08944f9681af2c1a582b646f>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Cecil.MetadataBuilder.AddTypes () [0x00018] in <4dd2191b08944f9681af2c1a582b646f>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Cecil.MetadataBuilder.BuildTypes () [0x00014] in <4dd2191b08944f9681af2c1a582b646f>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Cecil.MetadataBuilder.BuildModule () [0x0009f] in <4dd2191b08944f9681af2c1a582b646f>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Cecil.MetadataBuilder.BuildMetadata () [0x00000] in <4dd2191b08944f9681af2c1a582b646f>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Cecil.ModuleWriter+<>c.<BuildMetadata>b__2_0 (Mono.Cecil.MetadataBuilder builder, Mono.Cecil.MetadataReader _) [0x00000] in <4dd2191b08944f9681af2c1a582b646f>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Cecil.ModuleDefinition.Read[TItem,TRet] (TItem item, System.Func`3[T1,T2,TResult] read) [0x00029] in <4dd2191b08944f9681af2c1a582b646f>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Cecil.ModuleWriter.BuildMetadata (Mono.Cecil.ModuleDefinition module, Mono.Cecil.MetadataBuilder metadata) [0x0000f] in <4dd2191b08944f9681af2c1a582b646f>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Cecil.ModuleWriter.Write (Mono.Cecil.ModuleDefinition module, Mono.Disposable`1[T] stream, Mono.Cecil.WriterParameters parameters) [0x000fb] in <4dd2191b08944f9681af2c1a582b646f>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Cecil.ModuleWriter.WriteModule (Mono.Cecil.ModuleDefinition module, Mono.Disposable`1[T] stream, Mono.Cecil.WriterParameters parameters) [0x00002] in <4dd2191b08944f9681af2c1a582b646f>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Cecil.ModuleDefinition.Write (System.String fileName, Mono.Cecil.WriterParameters parameters) [0x00017] in <4dd2191b08944f9681af2c1a582b646f>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Cecil.AssemblyDefinition.Write (System.String fileName, Mono.Cecil.WriterParameters parameters) [0x00000] in <4dd2191b08944f9681af2c1a582b646f>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Linker.Steps.OutputStep.OutputAssembly (Mono.Cecil.AssemblyDefinition assembly) [0x0005d] in <52b04bb21b54415ab282c60622b3bc28>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Linker.Steps.OutputStep.ProcessAssembly (Mono.Cecil.AssemblyDefinition assembly) [0x00000] in <52b04bb21b54415ab282c60622b3bc28>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Linker.Steps.BaseStep.Process (Mono.Linker.LinkContext context) [0x00025] in <52b04bb21b54415ab282c60622b3bc28>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Mono.Linker.Pipeline.Process (Mono.Linker.LinkContext context) [0x00020] in <52b04bb21b54415ab282c60622b3bc28>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at MonoDroid.Tuner.Linker.Run (Mono.Linker.Pipeline pipeline, Mono.Linker.LinkContext context) [0x00000] in <52b04bb21b54415ab282c60622b3bc28>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at MonoDroid.Tuner.Linker.Process (MonoDroid.Tuner.LinkerOptions options, Mono.Linker.LinkContext& context) [0x00070] in <52b04bb21b54415ab282c60622b3bc28>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Xamarin.Android.Tasks.LinkAssemblies.Execute (Java.Interop.Tools.Cecil.DirectoryAssemblyResolver res) [0x002c8] in <52b04bb21b54415ab282c60622b3bc28>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Xamarin.Android.Tasks.LinkAssemblies.Execute () [0x00205] in <52b04bb21b54415ab282c60622b3bc28>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute () [0x00023] in <76dd0031e0df4aa99d9befb4c4585c69>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Common.targets(1628,5): error MSB4018:   at Microsoft.Build.BackEnd.TaskBuilder+<ExecuteInstantiatedTask>d__26.MoveNext () [0x0022d] in <76dd0031e0df4aa99d9befb4c4585c69>:0  [/Users/dave.thomas/Projects/androidTest/androidTest/androidTest.fsproj]
Comment 1 Jon Douglas [MSFT] 2017-09-28 17:42:33 UTC
I can CONFIRM this behavior on Windows as well using 15.4 Preview 3 (Xamarin.Android SDK 8.0.0.21)

I believe the following code is failing:

https://github.com/jbevain/cecil/blob/b03852f674e6f718d394dcbe7cc6293b32db2b50/Mono.Cecil/AssemblyWriter.cs#L2288

Which calls:

https://github.com/jbevain/cecil/blob/b03852f674e6f718d394dcbe7cc6293b32db2b50/Mono.Cecil/AssemblyWriter.cs#L2306-L2314

Marking the priority to HIGH - BLOCKER due to the severity of a linker issue.
Comment 2 Brendan Zagaeski (Xamarin Support) 2017-09-28 17:44:45 UTC
## Cross-reference for the Xamarin team

This candidate fix for Bug 59109 is https://github.com/jbevain/cecil/commit/22b36c3dc5dcc0ddba38164904a1b3daf02151e2 from 2017-08-30.


Xamarin.Android 8.0.0.21 (58645b2) does NOT contain this fix. It is based on:
https://github.com/xamarin/xamarin-android/tree/b3e6e27bf55348f5f2746d85114051eea6d4b9a6

Which references:

- https://github.com/xamarin/java.interop/tree/52559ef47a6486449be54bbcf26741c41fe390f7
  - https://github.com/mono/cecil/tree/362e2bb00fa693d04c2d140a4cd313eb82c78d95
  - Does NOT contain the fix: https://github.com/mono/cecil/commits/362e2bb00fa693d04c2d140a4cd313eb82c78d95/Mono.Cecil/AssemblyReader.cs was last changed on 2017-04-03

- https://github.com/mono/linker/tree/ebbd5b492321d092feae425e8f7aefc3c273530e
  - https://github.com/mono/cecil/tree/4cbf4a8d42cffb460d6394250dad8d81ae411693
  - Does NOT contain the fix: https://github.com/mono/cecil/commits/4cbf4a8d42cffb460d6394250dad8d81ae411693/Mono.Cecil/AssemblyReader.cs was last changed on 2017-03-28

(The tip of xamarin-android/d15-4 references these same 2 versions of mono/cecil.)


In contrast, xamarin-macios/d15-4 and xamarin-macios/d15-4-xi DO contain the fix:

- https://github.com/mono/mono/tree/bf21d1a2777b9505f3f0c26f51d3b600f296af38/external
  - https://github.com/mono/cecil/tree/d121ad986546f1a0f4c25cf3c41d2f7b595108fb
  - DOES contain the fix: https://github.com/mono/cecil/commits/d121ad986546f1a0f4c25cf3c41d2f7b595108fb/Mono.Cecil/AssemblyReader.cs was last changed on 2017-08-31
Comment 3 Dave Thomas 2017-09-29 10:26:52 UTC
Is it possible to get a hot fix to try this out, unless there a release coming soon?
Comment 4 Jonathan Pryor 2017-09-29 12:20:30 UTC
@Dave: This should be fixed in Xamarin.Android 8.0.0.35, which *may* make Visual Studio 15.4 Preview 4?

In the meantime, you can find hot-off-the-build-machines (~no QA) builds for d15-4 at: https://github.com/xamarin/xamarin-android#downloads
Comment 5 Jon Douglas [MSFT] 2017-10-02 14:34:50 UTC
*** Bug 59886 has been marked as a duplicate of this bug. ***
Comment 6 Cody Beyer (MSFT) 2017-10-05 18:15:40 UTC
Per comment 4
Comment 7 Roman Vaughan 2017-10-15 04:42:32 UTC
Visual Studio 15.4 contains Xamain.Android 8.0.0.33 which sadly does not contain the fix as the issue is still occurring...

Looking forward to Visual Studio 15.5 I guess....
Comment 9 Jonathan Pryor 2017-11-01 21:08:45 UTC
Background details on the cause of the bug:

https://bugzilla.xamarin.com/show_bug.cgi?id=59109#c7

> To be more thorough, the F# compiler is generating a scope with 1 constant,
> while there's zero constant in the constant table.

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