Bug 59109 - Linker fails to link assemblies: Reason: Object reference not set to an instance of an object (MT2001) (linker_test)
Summary: Linker fails to link assemblies: Reason: Object reference not set to an insta...
Status: VERIFIED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools ()
Version: XI 10.14 (d15-4)
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: 15.4
Assignee: Bugzilla
URL:
: 59427 ()
Depends on:
Blocks:
 
Reported: 2017-08-30 13:04 UTC by Dave Thomas
Modified: 2017-09-28 10:49 UTC (History)
11 users (show)

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


Attachments
build output (3.91 MB, text/plain)
2017-08-30 13:04 UTC, Dave Thomas
Details


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:
VERIFIED FIXED

Description Dave Thomas 2017-08-30 13:04:27 UTC
Created attachment 24476 [details]
build output

I have an F# iOS project which references a netstandard project, on building for a real device I get a linker failure:

MTOUCH: Error MT2001: Could not link assemblies. Reason: Object reference not set to an instance of an object (MT2001) (linker_test)

This is with:

Xamarin.iOS
Version: 10.14.0.24 (Visual Studio Community)
Hash: 43c281b4
Branch: d15-4
Build date: 2017-08-23 15:23:10-0400

I have a test project available here: https://github.com/7sharp9/linker_test

I have also attached the build output.

Any workaround for this would be appreciated as this is blocking any progress, I can also try any build you throw my way to shed more light on this issue.
Comment 1 Dave Thomas 2017-08-30 13:06:57 UTC
The test project is just a single view f# app referencing a netstandard2.0 lib, both come from the templates that come with vs4mac.  Its also worth noting that I have tried netstandard1.6 and different permutation of FSharp.Cor: 4.1.17, 4.1.18, 4.2.3
Comment 2 Sebastien Pouliot 2017-08-30 17:53:04 UTC
The failure happens when Cecil re-writes the .pdb file

    System.NullReferenceException: Object reference not set to an instance of an object
      at Mono.Cecil.MetadataBuilder.AddLocalConstants (Mono.Cecil.Cil.ScopeDebugInformation scope) [0x00011] in <02bda330e3df4b0a951856a277c73d92>:0 
      at Mono.Cecil.MetadataBuilder.AddLocalScope (Mono.Cecil.Cil.MethodDebugInformation method_info, Mono.Cecil.Cil.ScopeDebugInformation scope) [0x000b9] in <02bda330e3df4b0a951856a277c73d92>:0 
      at Mono.Cecil.MetadataBuilder.AddMethodDebugInformation (Mono.Cecil.Cil.MethodDebugInformation method_info) [0x0001f] in <02bda330e3df4b0a951856a277c73d92>:0 
      at Mono.Cecil.Cil.PortablePdbWriter.Write (Mono.Cecil.Cil.MethodDebugInformation info) [0x00006] in <02bda330e3df4b0a951856a277c73d92>:0 
      at Mono.Cecil.Cil.CodeWriter.WriteResolvedMethodBody (Mono.Cecil.MethodDefinition method) [0x000f1] in <02bda330e3df4b0a951856a277c73d92>:0 
      at Mono.Cecil.Cil.CodeWriter.WriteMethodBody (Mono.Cecil.MethodDefinition method) [0x0002b] in <02bda330e3df4b0a951856a277c73d92>:0 
      at Mono.Cecil.MetadataBuilder.AddMethod (Mono.Cecil.MethodDefinition method) [0x00013] in <02bda330e3df4b0a951856a277c73d92>:0 

c.c. JB
Comment 3 Jb Evain 2017-08-30 17:56:09 UTC
Could you please attach the DLL+PDB to the bug for a prompt resolution?
Thanks!
Comment 4 Vincent Dondain [MSFT] 2017-08-30 19:28:36 UTC
I can reproduce this issue, it indeed fails on device with Xamarin.iOS 10.14.0.24.

Doesn't seem to be the same cause as https://bugzilla.xamarin.com/show_bug.cgi?id=58063 since the test cases provided in the other bug still work for me with Xamarin.iOS 10.14.0.24 and the stack trace for this test case looks different.

Also it's broken in 15.3 so not an immediate regression.
Comment 5 Vincent Dondain [MSFT] 2017-08-30 19:38:29 UTC
@jb is that what you want? https://www.dropbox.com/s/wjcfytt8n83z9vg/mtouch-cache-bug-59109.zip?dl=0

The mtouch-cache with .dll and .pdb files?
Comment 6 Jb Evain 2017-08-30 21:38:36 UTC
Fixed upstream in:

https://github.com/jbevain/cecil/commit/22b36c3dc5dcc0ddba38164904a1b3daf02151e2

The F# compiler is generating an invalid constant entry in the portable pdb.
Comment 7 Jb Evain 2017-08-30 21:39:33 UTC
To be more thorough, the F# compiler is generating a scope with 1 constant, while there's zero constant in the constant table.
Comment 8 Sebastien Pouliot 2017-08-30 22:01:24 UTC
@Marek can you update mono/cecil with this fix ? thanks!
Comment 9 Marek Safar 2017-08-31 12:15:13 UTC
Which branch should this go in?
Comment 10 Sebastien Pouliot 2017-08-31 13:17:22 UTC
@Marek, right now we need it in the cecil submodule that `d15-4-2017-04` points too.
But please also add it in `d15-4-2017-06` in case we're able to make it. Thanks!
Comment 11 Dave Thomas 2017-08-31 13:23:28 UTC
Is there an ETA on a patched version to try?  I don't think there is currently a work around.
Comment 12 Dave Thomas 2017-08-31 16:19:08 UTC
I did try to build with linking disabled but got this error:

MTOUCH : error MT3001: Could not AOT the assembly '/Users/dave.thomas/Documents/scarletwitch-mobile/ScarletWitch.Mobile.iOS/obj/iPhone/Debug/mtouch-cache/Build/scarletwitch-mobile.dll'
      at Xamarin.Bundler.AOTTask+<ExecuteAsync>d__14.MoveNext () [0x0023e] in /Users/builder/data/lanes/5143/43c281b4/source/xamarin-macios/tools/mtouch/BuildTasks.mtouch.cs:256 
    --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:151 
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 
      at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 
      at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:113 
      at Xamarin.Bundler.BuildTask+<Execute>d__22.MoveNext () [0x002b9] in /Users/builder/data/lanes/5143/43c281b4/source/xamarin-macios/tools/common/BuildTasks.cs:247 
    --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:151 
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 
      at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 
      at System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult () [0x00000] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:357 
      at Xamarin.Bundler.BuildTask+<Execute>d__22.MoveNext () [0x00380] in /Users/builder/data/lanes/5143/43c281b4/source/xamarin-macios/tools/common/BuildTasks.cs:258 
    --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:151 
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 
      at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 
      at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:113 
      at Xamarin.Bundler.BuildTask+<Execute>d__22.MoveNext () [0x00380] in /Users/builder/data/lanes/5143/43c281b4/source/xamarin-macios/tools/common/BuildTasks.cs:258 
    --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:151 
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 
      at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 
      at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:113 
      at Xamarin.Bundler.BuildTask+<Execute>d__22.MoveNext () [0x00380] in /Users/builder/data/lanes/5143/43c281b4/source/xamarin-macios/tools/common/BuildTasks.cs:258 
    --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:151 
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 
      at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 
      at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:113 
      at Xamarin.Bundler.BuildTask+<Execute>d__22.MoveNext () [0x00380] in /Users/builder/data/lanes/5143/43c281b4/source/xamarin-macios/tools/common/BuildTasks.cs:258 
    --- End of stack trace from previous location where exception was thrown ---
      at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x0000c] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/exceptionservices/exceptionservicescommon.cs:151 
      at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Threading.Tasks.Task task) [0x00037] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:187 
      at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Threading.Tasks.Task task) [0x00028] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:156 
      at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd (System.Threading.Tasks.Task task) [0x00008] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:128 
      at System.Runtime.CompilerServices.TaskAwaiter.GetResult () [0x00000] in /Users/builder/data/lanes/4992/mono-mac-sdk/external/bockbuild/builds/mono-x64/mcs/class/referencesource/mscorlib/system/runtime/compilerservices/TaskAwaiter.cs:113 
      at Xamarin.Bundler.BuildTasks+<>c__DisplayClass4_0+<<ExecuteBuildTasks>b__0>d.MoveNext () [0x0002e] in /Users/builder/data/lanes/5143/43c281b4/source/xamarin-macios/tools/common/BuildTasks.cs:49
Comment 13 Dave Thomas 2017-09-06 17:12:38 UTC
When is Future Cycle (TBD) likely to be?  At the moment Im having to build cecil locally and patch my Xamarin.iOS install, I don't really want to have to write a script to do that on out CI server though.
Comment 14 Luis Aguilera 2017-09-13 01:51:17 UTC
@Dave we're going to try to get this in for the upcoming 15.4 Preview 3, which is due out in ~2 weeks.
Comment 15 Sebastien Pouliot 2017-09-13 13:07:53 UTC
*** Bug 59427 has been marked as a duplicate of this bug. ***
Comment 17 Sebastian Fialka 2017-09-15 20:29:21 UTC
Some problem here with a very important project. Would be great to see this fixed ASAP!