Bug 58789 - [mtouch] NullReferenceException / MT0000 (while reporting another error)
Summary: [mtouch] NullReferenceException / MT0000 (while reporting another error)
Status: VERIFIED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools (show other bugs)
Version: XI 10.12 (d15-3)
Hardware: PC Mac OS
: Highest blocker
Target Milestone: 15.3
Assignee: Sebastien Pouliot
URL:
: 58768 58777 58784 58820 58825 58874 58931 58978 (view as bug list)
Depends on:
Blocks: 58834
  Show dependency tree
 
Reported: 2017-08-15 19:49 UTC by Sebastien Pouliot
Modified: 2017-09-06 07:59 UTC (History)
19 users (show)

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


Attachments
mtouch fix for MT0000 (388.58 KB, application/zip)
2017-08-15 20:20 UTC, Sebastien Pouliot
Details
ios build output (6.40 MB, text/plain)
2017-08-16 15:05 UTC, Yuri
Details

Description Sebastien Pouliot 2017-08-15 19:49:25 UTC
There is an issue when `mtouch` tries to report a MT2102 error [1]. The additional information being reported sadly cause a `NullReferenceException` which results in less (not more) information about the original issue.

[1] https://github.com/xamarin/xamarin-macios/pull/1960/files#diff-2b36cc422b45c69c319e43593341df85R94

Since this exception happens in the MT2xxx (linker) exception handler it gets reported as an MT0000 by the top-level handler. This will look like this:

> MTOUCH: error MT0000: Unexpected error - Please file a bug report at http://bugzilla.xamarin.com
>		System.NullReferenceException: Object reference not set to an instance of an object
>		  at MonoTouch.Tuner.Linker.Process (MonoTouch.Tuner.LinkerOptions options, MonoTouch.Tuner.MonoTouchLinkContext& context, System.Collections.Generic.List`1[Mono.Cecil.AssemblyDefinition]& assemblies) [0x00145]
Comment 1 Sebastien Pouliot 2017-08-15 19:52:11 UTC
*** Bug 58768 has been marked as a duplicate of this bug. ***
Comment 2 Sebastien Pouliot 2017-08-15 19:53:56 UTC
*** Bug 58784 has been marked as a duplicate of this bug. ***
Comment 3 Sebastien Pouliot 2017-08-15 19:54:49 UTC
*** Bug 58777 has been marked as a duplicate of this bug. ***
Comment 4 Sebastien Pouliot 2017-08-15 20:20:42 UTC
Created attachment 24207 [details]
mtouch fix for MT0000

The attached .zip file contains an updated version of mtouch.exe and mtouch.pdb (the corresponding debugging symbols).

The content of the zip should only be used to replace `mtouch` on a Mac for version 10.12.0.0 to 10.12.0.18.

To use this please start by doing a backup of the files, e.g.

> cp /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mtouch/mtouch.* ~/

Then extract the archive over the original ones, e.g.

> unzip ~/Download/mtouch58789.zip -d /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mtouch/

If asked confirm (y) to overwrite over the files.

Finally clean your solution and build again. Your build should now report an MT2102 error including details like the method name, the assembly name and the reason they could not be processed.
Comment 5 Sebastien Pouliot 2017-08-15 21:16:20 UTC
*** Bug 58791 has been marked as a duplicate of this bug. ***
Comment 6 Yuri 2017-08-15 21:34:03 UTC
I don't have "Current" folder but I do have "10.12.0.18" folder which I assume has correct files.
Comment 7 Yuri 2017-08-15 21:41:03 UTC
Sebastien, do you have VS2017 Preview installed?
Comment 8 Sebastien Pouliot 2017-08-15 21:49:26 UTC
@Yuri in your case `Current` should be a symlink to the `10.12.0.18` folder, it's a way to simplify scripting over different versions of our SDK. Copying inside the `.../10.12.0.18/lib/mtouch/` will be identical.

WRT "VS2017 Preview" I run exclusively on macOS, we have a separate team to handle the VS/Windows extension. However the attached fix should work from Windows too (since mtouch is executed on the macOS side).
Comment 9 Yuri 2017-08-15 21:52:42 UTC
I wrote files from zip file and started to get strange errors about Grid constructor. So, I rolled back original files, removing 2017 Preview and repair VS2017 stable version. Then I will go from there
Comment 10 Sebastien Pouliot 2017-08-15 22:01:13 UTC
@Yuri, the exception causing the `MT0000` was inside a block reporting another error. So it's perfectly normal and expected that you'll get a `MT2102` error after applying the fix. If you want you can reply with more details (e.g. new build logs) in your original bug report.

In any case there is no need to repair VS2017 (from Windows). You can replace your original files (if you wish, the only change is how the MT2102 error is reported). Only clean your solution and rebuild it is needed between the changes (of files).
Comment 11 Brendan Zagaeski (Xamarin Support) 2017-08-15 23:47:35 UTC
*** Bug 58796 has been marked as a duplicate of this bug. ***
Comment 12 Alex Soto [MSFT] 2017-08-16 01:40:05 UTC
*** Bug 58762 has been marked as a duplicate of this bug. ***
Comment 13 Yuri 2017-08-16 05:12:09 UTC
With files from zip I am getting the follow:

Severity	Code	Description	Project	File	Line	Suppression State
Error		Error processing the method 'System.Void Xamarin.Forms.DataGrid.DataGridColumn/<>c::.cctor()' in the assembly 'Xamarin.Forms.DataGrid.dll': Value cannot be null.	ButtonRendererDemo.iOS			

Error	Metadata	Error while reading 'C:\Temp\Xamarin\ButtonRendererDemo\ButtonRendererDemo\ButtonRendererDemo.iOS\obj\iPhone\Debug\ButtonRendererDemoiOS.exe': Could not find a part of the path 'C:\Temp\Xamarin\ButtonRendererDemo\ButtonRendererDemo\ButtonRendererDemo.iOS\obj\iPhone\Debug\ButtonRendererDemoiOS.exe'.	ButtonRendererDemo.iOS		1	Active

What are next steps to fix that?
Comment 14 Omar 2017-08-16 07:33:46 UTC
I also received a similar error after replacing mtouch.exe as mentioned above.

4>C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(748,3): error : Error processing the method 'System.Void ProjectName.Forms.Constants::.cctor()' in the assembly 'ProjectName.Forms.dll': Value cannot be null.
4>  Parameter name: instruction

My ProjectName.Forms.Constants class is a simply like:

public static class Constants
{

    #region Messages 
    public static readonly string UserAction = "UserAction";
    public static readonly string ICMessage = "IC";
    public static readonly string ULIMessage = "ULI";
    public static readonly string ULOMessage = "ULO";
    public static readonly string UHPI = "UHPI";
    public static readonly string CIR = "CIR";
    public static readonly string CIROFI = "CIROFI";
    public static readonly string CIRR = "CIRR";
    public static readonly string USTC = "USTC";
    public static readonly string UGDI = "UGDI";
    public static readonly string ITC = "ITC";
    public static readonly string ONS = "ONS";
    #endregion

    public static readonly int DPS = 30;
    public static readonly TimeSpan DCT = TimeSpan.FromMinutes(60);
}
Comment 15 chaaaau 2017-08-16 09:45:09 UTC
For me, replacing the mtouch files game the following error:

/Users/nischal/Desktop/c2mservice/iOS/MTOUCH: Error MT2102: Error processing the method 'System.Void Couchbase.Lite.Storage.SQLCipher.SqliteCouchStore/<GetDocNumericID>c__AnonStorey6::.ctor()' in the assembly 'Couchbase.Lite.Storage.SQLCipher.dll': Value cannot be null. (MT2102) (Connect2Metrics.iOS)

I've since tried removing and re-adding the said package, but no luck
Comment 16 Luis 2017-08-16 11:47:46 UTC
I am getting similar issues - replacing the mtouch files I now get the following error when building from a VS2015 windows agent on a mac that is running xamarin studio.

C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(748,3): error : Error processing the method 'System.Void Name.Class::.cctor()' in the assembly 'Name.dll': Value cannot be null.
Comment 17 Sebastien Pouliot 2017-08-16 12:33:27 UTC
There is a high probability that the MT2102 issues you're facing are identical (or variations) but they could be different in some cases.


What we need now are full build logs (see below) to see a complex stack trace and the binaries to analyze, e.g. for an error showing:

> ,,, in the assembly 'Name.dll' ...

We need to have `Name.dll`, `Name.pdb` and `Name.dll.mdb` (it's likely that only one of the debugging symbols will be present, not both) attached to the bug report.

This is a different issue than the MT0000 and you might want those information to be private. Please open a new bug report (or reuse your original one) to provide the information confidentially. Thank you all!




Please include your full build logs, all your version information and the most important thing a test case (to reproduce).

To get full build logs just set the log verbosity to diagnostic at the following locations:
- On Visual Studio for Mac: Preferences > Projects > Build
- On Visual Studio for Windows: Tools > Options > Projects and Solutions > Build and Run

On Visual Studio Windows you also want to add `-v -v -v -v` to the mtouch additional arguments by right-clicking the project in the solution explorer and selecting `Properties`.
Note: this is done automatically on Visual Studio for Mac when the log verbosity is set to diagnostic.
Comment 18 Luis 2017-08-16 13:50:34 UTC
The build that is failing for us is our current release branch, which uses xamarin.forms 2.3.4.231.
Our dev branch, which is on a slightly newer xamarin.forms 2.3.4.247, did manage to build successfully on iOS#AppStore configuration, through what is essentially the same build definition/agent/mac combo.

Now having another go at the release branch with an updated xamarin.forms package, but it hasn't been successful yet (for other reasons).
Comment 19 Yuri 2017-08-16 15:05:10 UTC
Created attachment 24243 [details]
ios build output

This is diagnostic and "-v ..." output window. I am not sure where to get log file if you still need it.
Comment 20 Luis 2017-08-16 15:48:44 UTC
Just adding that the build that was failing beforehand did indeed work after updating xamarin.forms from 2.3.4.231 to 2.3.4.247.
Comment 21 Yuri 2017-08-16 16:01:04 UTC
I am using 2.3.4.247 but no luck
Comment 22 Yuri 2017-08-16 19:15:03 UTC
I am still stack. Any suggestions?
Comment 23 Alex Soto [MSFT] 2017-08-16 22:04:00 UTC
*** Bug 58825 has been marked as a duplicate of this bug. ***
Comment 24 Sebastien Pouliot 2017-08-16 22:05:17 UTC
@Luis there was an issue [1] with XF's `xamlc` not updating the debug symbols (pdb) file that was fixed in the newer version of XF that you're using [2].

[1] https://bugzilla.xamarin.com/show_bug.cgi?id=56296
[2] https://developer.xamarin.com/releases/xamarin-forms/xamarin-forms-2.3/2.3.4-sr2/#2.3.4.247_Service_Release_2

Now this might not be an XF issue in every case but incorrect (or out of sync) debug symbols can lead to build failures.

One way to check this in your builds would be to delete the debug symbols (copy them first) for the assembly mentioned sin the MT2102 error message. 

E.g. if the error is reported on `Name.dll` then delete all copies of `Name.pdb` and `Name.dll.mdb` inside your project (only one should exists).


Note: that should not be an issue if you build the mentioned assembly from sources (unless the old `xcmlc` is used) but, if you're using binaries (e.g. nuget) then it's worth trying (since it will be hard to know of it was produced).
Comment 25 Brendan Zagaeski (Xamarin Support) 2017-08-17 00:21:58 UTC
*** Bug 58820 has been marked as a duplicate of this bug. ***
Comment 26 Yuri 2017-08-17 01:35:18 UTC
@Sebastain I cannot remove Xamarin DLL which I am getting error from. I see chaaaau is getting similar issue also about some constructor. What are we suppose to do?
Comment 27 Sebastien Pouliot 2017-08-17 01:47:09 UTC
@Yuri please read carefully. You have never been told to remove any .dll, you need those files.

The file(s) that should be removed are not the code (.dll) but the debugging symbols, i.e. with a `.pdb` or `.dll.mdb` extension. Just in case make sure to create a copy of the files before deleting them.

If the build works without the debug symbols (for the mentioned assembly in the MT2102 error) then it's a good indication that they are either corrupted (or out of sync). In that case you'll need to update your package for those files.
Comment 28 Yuri 2017-08-17 01:50:09 UTC
@Sebastain thank you. Can you please tell me the location of those `.pdb` or `.dll.mdb` files. Are they on Windows (I am using VS 2017) or MAC?
Comment 29 Sebastien Pouliot 2017-08-17 02:16:42 UTC
@Yuri from the logs you attached your error is:

2>C:\Program Files (x86)\MSBuild\Xamarin\iOS\Xamarin.iOS.Common.targets(748,3): error : Error processing the method 'System.Void Xamarin.Forms.DataGrid.DataGridColumn/<>c::.cctor()' in the assembly 'Xamarin.Forms.DataGrid.dll': Value cannot be null.

So you're looking for a `Xamarin.Forms.DataGrid.pdb` file which (from your logs) seems to located in

C:\Temp\Xamarin\ButtonRendererDemo\packages\Xamarin.Forms.DataGrid.1.9.2\lib\portable-win+net45+wp80+win81+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10\Xamarin.Forms.DataGrid.pdb

note: there's no sign of a `Xamarin.Forms.DataGrid.dll.mdb` file (which is normal, both formats should not exists at the same time).

Next copy that file (e.g. to your desktop) and then delete it (from the above location).

Make sure to clean your solution before building it - because copies of the .pdb file might exists in your cached/temporary build files. You can double check your build log to ensure the string `Xamarin.Forms.DataGrid.pdb` is nowhere to be seen.
Comment 30 Andy 2017-08-17 14:45:53 UTC
This is the error that I get:

Error processing the method 'System.Void SQLiteNetExtensions.Extensions.ReadOperations::GetChildrenRecursive(SQLite.Net.SQLiteConnection,System.Object,System.Boolean,System.Boolean,System.Collections.Generic.Dictionary`2<System.String,System.Collections.Generic.Dictionary`2<System.Object,System.Object>>)' in the assembly 'SQLiteNetExtensions.dll': Value cannot be null.

which is caused by the following:

using ObjectCache = Dictionary<string, Dictionary<object, object>>;

in:

https://bitbucket.org/twincoders/sqlite-net-extensions/src/ffa73e87ab948c1dd3d584572bcbdab19d65a17a/SQLiteNetExtensions/Extensions/ReadOperations.cs?at=master&fileviewer=file-view-default

line 15.

This is valid C# so it seems like the linker doesn't work with using statements declared at the class level
Comment 31 John Hardman 2017-08-17 16:25:33 UTC
I applied the patch from comment 4 of https://bugzilla.xamarin.com/show_bug.cgi?id=58789, downgraded the Xamarin.Auth version used in my iOS build to 1.3.2.7 (thankfully, I had already arranged my Xamarin.Auth related code such that I can use different versions for different platforms), and turned off linking. That combination got things working again for me.
Comment 32 Yuri 2017-08-17 22:02:51 UTC
@Sebastien So here what happens. 
I have 2 files in project when I download the Grid package dated 06/06/2017
- Xamarin.Forms.DataGrid.dll
- Xamarin.Forms.DataGrid.pdb

When I build the project another file shows up dated today
- Xamarin.Forms.DataGrid.dll.mdb
and build fails

After I delete pdb file only and kept mdb the build still fails
After I delete both pdb and mdb files rebuild succeeds and no mdb files shows in the folder.
What is the next step to return debug symbols back?
Comment 33 Yuri 2017-08-17 22:30:16 UTC
I just realised that DataGrid is third-party software. I can remove it completely but that will require to rewrite some of my code or it can be fixed.Please advice.
Comment 34 Brendan Zagaeski (Xamarin Support) 2017-08-17 22:52:56 UTC
Based on some follow-up investigation of the linker errors (the ones that appear after applying the patch from Comment 4), it appears that the underlying problem is in some sense a "version mismatch" where a fix for a bug in Mono.Cecil [1] has not yet been integrated as expected into Xamarin.iOS.

I suspect it might not be possible to work around the issue with the existing binaries of Xamarin.iOS 10.12, so I believe the next step will be for the Xamarin.iOS team to integrate the Mono.Cecil change and test a candidate build that includes the fix.  I will check with the team about the quickest way to share the (in-progress) candidate fix with users too.

[1] https://github.com/mono/cecil/commit/16d23978e7084c910b47f84092a5c546d880ae48
Comment 35 Johan 2017-08-18 07:53:53 UTC
@Yuri, I also had trouble with "MTOUCH: Error MT2102 ...   ::.ctor()' in the assembly 'name.dll': Value cannot be null. I fixed this by deleting all the bin/obj folders and also the project.lock.json file. Maybe this helps for you.
Comment 36 Sebastien Pouliot 2017-08-18 14:59:43 UTC
PR for d15-3 https://github.com/xamarin/xamarin-macios/pull/2510
Comment 37 Brendan Zagaeski (Xamarin Support) 2017-08-18 17:46:34 UTC
*** Bug 58874 has been marked as a duplicate of this bug. ***
Comment 38 Brendan Zagaeski (Xamarin Support) 2017-08-18 23:36:43 UTC
An experimental installer package with the candidate fix for the MT0000 issue as well as the follow-up MT2102 errors is now available.

For any user who might like to try that experimental version, see Bug 58834, Comment 10 for the download link and information about installing and uninstalling it.
Comment 39 Sebastien Pouliot 2017-08-21 15:12:04 UTC
Merged in https://github.com/xamarin/xamarin-macios/commit/80b8487d5d9bfcb845ee9636082c9a7d1fb59076
To be released in upcoming SR2
Comment 40 Brendan Zagaeski (Xamarin Support) 2017-08-21 20:36:23 UTC
*** Bug 58931 has been marked as a duplicate of this bug. ***
Comment 41 Brendan Zagaeski (Xamarin Support) 2017-08-22 22:25:16 UTC Comment hidden (obsolete)
Comment 42 Brendan Zagaeski (Xamarin Support) 2017-08-22 22:27:21 UTC
## Status update for any users watching this issue

The candidate fix for this issue has now been published to the Stable and Beta updater channels as part of Xamarin.iOS 10.12.0.20 in the Xamarin 15.3.2 Servicing Release [1].

[1] https://releases.xamarin.com/stable-release-15-3-2/
Comment 43 Sebastien Pouliot 2017-08-23 20:51:56 UTC
*** Bug 58978 has been marked as a duplicate of this bug. ***
Comment 45 Brendan Zagaeski (Xamarin Support) 2017-08-24 15:08:45 UTC
This bug is verified fixed, and the fix is released.  No further action by QA is required.

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