Bug 51670 - MTOUCH: Error MT6002: Could not strip assembly /obj/iPhone/Release/mtouch-cache/64/Build/System.Net.Http.Primitives.dll
Summary: MTOUCH: Error MT6002: Could not strip assembly /obj/iPhone/Release/mtouch-cac...
Status: RESOLVED DUPLICATE of bug 51805
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools ()
Version: XI 10.4 (C9)
Hardware: Macintosh Mac OS
: High critical
Target Milestone: (C9)
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2017-01-20 19:28 UTC by dhaligas
Modified: 2017-01-30 22:58 UTC (History)
5 users (show)

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


Attachments
System.Net.Http.Primatives.dll (5.00 KB, application/x-msdownload)
2017-01-20 19:47 UTC, dhaligas
Details
buildlog (797.71 KB, text/plain)
2017-01-20 19:53 UTC, dhaligas
Details
buildlogverbose (1.17 MB, text/plain)
2017-01-20 22:39 UTC, dhaligas
Details
buildlog-stable (1.29 MB, text/plain)
2017-01-23 20:05 UTC, dhaligas
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:
RESOLVED DUPLICATE of bug 51805

Description dhaligas 2017-01-20 19:28:12 UTC
I am seeing Could not strip assembly errors with Cycle 9.  This does not occur with Stable.

This bug occurs on AppStore Release build with Strip Native Symbols checked.   

The dll in question comes from the Microsoft.Net.Http Nuget Package
The app also has ModernHttpClient installed

# Steps to reproduce
1. Select iOS App -> Release -> Device
2. Click Build -> Archive for Publishing 

# Expected behavior
Builds succeeds 

# Actual behavior
Build Fails with the following error 
MTOUCH: Error MT6002: Could not strip assembly /obj/iPhone/Release/mtouch-cache/64/Build/System.Net.Http.Primitives.dll. (MT6002)

# Supplemental info (logs, images, videos)
MTOUCH: Error MT6002: Could not strip assembly /obj/iPhone/Release/mtouch-cache/64/Build/System.Net.Http.Primitives.dll. (MT6002)

# Test environment (full version information)
=== Xamarin Studio Enterprise ===

Version 6.2 (build 1757)
Installation UUID: 83b4c80f-9e4a-4988-a8be-b906dee1f4a1
Runtime:
	Mono 4.8.0 (mono-4.8.0-branch/cd26828) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 408000459

=== NuGet ===

Version: 3.5.0.0

=== Xamarin.Profiler ===

Version: 1.1.5
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Apple Developer Tools ===

Xcode 8.2 (11766)
Build 8C38

=== Xamarin.iOS ===

Version: 10.4.0.88 (Visual Studio Enterprise)
Hash: 9975cb1
Branch: cycle9
Build date: 2017-01-13 10:35:52-0500

=== Xamarin.Mac ===

Version: 3.0.0.358 (Visual Studio Enterprise)

=== Xamarin.Android ===

Version: 7.1.0.23 (Visual Studio Enterprise)
Android SDK: /Users/sdk/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
		5.1    (API level 22)
		6.0    (API level 23)
		7.0    (API level 24)
		7.1    (API level 25)

SDK Tools Version: 25.2.3
SDK Platform Tools Version: 25
SDK Build Tools Version: 25.0.1

Java SDK: /usr
java version "1.8.0_40"
Java(TM) SE Runtime Environment (build 1.8.0_40-b26)
Java HotSpot(TM) 64-Bit Server VM (build 25.40-b25, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin Android Player ===

Version: 0.6.5
Location: /Applications/Xamarin Android Player.app

=== Xamarin Inspector ===

Version: 1.0.0.0
Hash: 1f3067d
Branch: master
Build date: Tue, 15 Nov 2016 21:13:59 GMT

=== Build Information ===

Release ID: 602001757
Git revision: d769a24532f7b7a9933fc9187631b4175fb94be6
Build date: 2017-01-17 15:00:00-05
Xamarin addins: 3fda1860d20ac17fb238c320a021b07d96dc9e53
Build lane: monodevelop-lion-cycle9

=== Operating System ===

Mac OS X 10.11.6
Darwin HA003311 15.6.0 Darwin Kernel Version 15.6.0
    Wed Nov  2 20:30:56 PDT 2016
    root:xnu-3248.60.11.1.2~2/RELEASE_X86_64 x86_64

=== Enabled user installed addins ===

NuGet Package Management Extensions 0.12
Prism Template Pack 1.5
Redth's Addins 1.0.4
Comment 1 Sebastien Pouliot 2017-01-20 19:33:52 UTC
Please attach

1. your full release build log; and

2. `obj/iPhone/Release/mtouch-cache/64/Build/System.Net.Http.Primitives.dll` so we can be sure we're not picking a different version (or that the build modified it).

Thanks!
Comment 2 dhaligas 2017-01-20 19:47:27 UTC
Created attachment 19418 [details]
System.Net.Http.Primatives.dll
Comment 3 dhaligas 2017-01-20 19:53:16 UTC
Created attachment 19419 [details]
buildlog
Comment 4 Sebastien Pouliot 2017-01-20 20:19:40 UTC
For some reason `mono-cil-strip` does not like the assembly. The tool ships with mono but even stable (4.6) fails identically, so it's likely a build issue.


castor:tests poupou$ mono-cil-strip ~/Downloads/System.Net.Http.Primitives.dll snhp.dll
Mono CIL Stripper

Error: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
  at System.Collections.CollectionBase.System.Collections.IList.get_Item (System.Int32 index) [0x00022] in <111faffb08a0411a893ed183e82e8c28>:0 
  at Mono.Cecil.AssemblyNameReferenceCollection.get_Item (System.Int32 index) [0x00006] in <f824991ee86549dd978744e0200e442f>:0 
  at Mono.Cecil.ReflectionReader.GetExportedTypeScope (Mono.Cecil.Metadata.MetadataToken scope) [0x00043] in <f824991ee86549dd978744e0200e442f>:0 
  at Mono.Cecil.ReflectionReader.VisitExternTypeCollection (Mono.Cecil.ExternTypeCollection externs) [0x00089] in <f824991ee86549dd978744e0200e442f>:0 
  at Mono.Cecil.AggressiveReflectionReader.ReadExternTypes () [0x0000c] in <f824991ee86549dd978744e0200e442f>:0 
  at Mono.Cecil.AggressiveReflectionReader.VisitTypeDefinitionCollection (Mono.Cecil.TypeDefinitionCollection types) [0x0004f] in <f824991ee86549dd978744e0200e442f>:0 
  at Mono.Cecil.ReflectionReader.VisitModuleDefinition (Mono.Cecil.ModuleDefinition mod) [0x00007] in <f824991ee86549dd978744e0200e442f>:0 
  at Mono.Cecil.StructureReader.TerminateAssemblyDefinition (Mono.Cecil.AssemblyDefinition asm) [0x00034] in <f824991ee86549dd978744e0200e442f>:0 
  at Mono.Cecil.AssemblyDefinition.Accept (Mono.Cecil.IReflectionStructureVisitor visitor) [0x0001f] in <f824991ee86549dd978744e0200e442f>:0 
  at Mono.Cecil.AssemblyFactory.GetAssembly (Mono.Cecil.Binary.ImageReader irv, System.Boolean manifestOnly) [0x00014] in <f824991ee86549dd978744e0200e442f>:0 
  at Mono.Cecil.AssemblyFactory.GetAssembly (Mono.Cecil.Binary.ImageReader reader) [0x00000] in <f824991ee86549dd978744e0200e442f>:0 
  at Mono.Cecil.AssemblyFactory.GetAssembly (System.String file) [0x00006] in <f824991ee86549dd978744e0200e442f>:0 
  at Mono.CilStripper.Program.Main (System.String[] args) [0x00029] in <f824991ee86549dd978744e0200e442f>:0 


@dhaligas could you re-attach the build logs with `-v -v -v -v` in the **mtouch additional arguments**. The current build does not show me enough details to see where the file is being modified. Thanks!
Comment 5 dhaligas 2017-01-20 20:32:13 UTC
@sebastian doing that now

I noticed that is it coming from mtouch-cache but I created another project from scratch and it doesn't have a problem.

Is there a xamarin project cache hidden I need to clean?
Comment 6 Sebastien Pouliot 2017-01-20 20:39:58 UTC
> Is there a xamarin project cache hidden I need to clean?

Nothing special, i.e. if you do a "Clean" or a "Rebuild" then the cache will be deleted (and the next build will starts from scratch).

> I created another project from scratch and it doesn't have a problem.

There are other reasons why a new project might not fail, e.g. it might not be reference in the final app.

The main problem is that the Microsoft.Net.Http _tries_ to replace something (System.Net.Http.Primitives.dll) that XI ships. That's tricky since any new release of XI can (and does) ship different/newer versions of it's BCL and any assumption made by the (older) nuget might not be true anymore.

However the above generally creates issues at build time or runtime. The fact that it happens while stripping the IL might indicate a different issue (e.g. some kind of mix up between XI and the Nuget assembly).
Comment 7 dhaligas 2017-01-20 20:49:15 UTC
@sebastian I have gotten this error on 2 different machines with 2 different existing projects.

kind of at a loss.

should we use the xamarin one?

I have a package that requires it: Branch-Xamarin-Linking-SDK
Comment 8 Sebastien Pouliot 2017-01-20 21:48:55 UTC
I never used Branch-Xamarin-Linking-SDK. I suspect there was a good reason at some point to use the nuget, but it's likely not required anymore. Sadly it's not of an huge/immediate help to you.

As for Microsoft.Net.Http nuget [1] has not been updated for nearly 2 years now and the Xamarin platform has changed a lot since then - and we're shipping MS code that's newer than this in many places.

[1] https://www.nuget.org/packages/Microsoft.Net.Http/

In any case I'd like to investigate this further using more verbose logs or, if possible, with a test case that duplicates the issue. Thanks for your help!
Comment 9 dhaligas 2017-01-20 21:53:07 UTC
@sebastian what should we use to code in PCL then for System.Net.Http?
Comment 10 dhaligas 2017-01-20 22:39:00 UTC
Created attachment 19420 [details]
buildlogverbose
Comment 11 dhaligas 2017-01-20 22:39:28 UTC
@sebastian add another build log .. this will be a blocker for us if this goes to stable
Comment 12 dhaligas 2017-01-23 15:25:46 UTC
@sebastian I am having trouble recreating this on a new project but that is not helpful since there are a lot of us out there using Microsoft.Net.Http due to the PCL profile support and other Nugets depending on it.  

Like I stated before this works on stable and fails on beta. 

Did something change in the mono build process?  Let me know what more info I can get you.
Comment 13 Sebastien Pouliot 2017-01-23 16:50:14 UTC
> but that is not helpful

If I cannot duplicate the issue then I can't be sure it's fixed, nor can QA confirm a potential fix to get released.

I'll give it a try myself (in meeting this week) based on your description - but if you can't duplicate it seems I'll have similar problems.

In general using a copy of your application and cutting pieces (and testing it still fails) is the best way to get small test case.


> due to the PCL profile support

It's an unneeded dependency, see HTTPClient in [1]. The only reason to use this would be to support .NET 4.0.x, Windows Phone / Silverlight (not Xamarin).

[1] https://msdn.microsoft.com/en-us/library/gg597391.aspx

> other Nugets depending on it

I understand it might be an indirect dependency for you - but it does not make it a correct one. You might want to file issue with the Branch-Xamarin-Linking-SDK package not to use the nuget.

Even fixing the current issue (at strip time) does not mean this is safe to use (it's trying to replace an assembly from the SDK with one that is 2 years old, today). It _might_ work but any assumption this requires could break at any time.
Comment 14 dhaligas 2017-01-23 16:55:27 UTC
@sebastian thanks for the response.  I will see what I can do to make this build work.  

Just giving you a heads up that a lot of apps out there will experience this issue, since people using Xamarin.Forms are targeting Profile78 in PCL which doesn't include System.Net.Http
Comment 15 Sebastien Pouliot 2017-01-23 17:46:10 UTC
Part of my above comments where made for System.Net.Primitives.dll and not System.Net.Http.Primitives.dll, so I need to review this again (with more caffeine).
Comment 16 Sebastien Pouliot 2017-01-23 18:39:56 UTC
1. System.Net.Http.dll
2. System.Net.Http.Primitives.dll
3. System.Net.Http.Extensions.dll

#1 should be discarded and the newer one (from our SDK) be used.

#2 and #3 should not be used directly (as it would not be "ok" wrt other platforms that don't require the nuget to provide httpclient).

However since #2 is still part of the build then a reference exists somewhere.

Can you:

a. give me the same full (-v -v -v -v) build log using the stable releases ?

b. zip and attach the binaries under `/Users/dahaligas/src/glad/gthy-pro-mobile/Core/Glad.iOS/obj/iPhone/Release/mtouch-cache/64/Build/*`

While not a good as a test case that should give me clues where things changed. Thanks!
Comment 17 dhaligas 2017-01-23 20:05:57 UTC
Created attachment 19450 [details]
buildlog-stable
Comment 18 dhaligas 2017-01-23 20:12:05 UTC
@sebastian this appears to be a Mono.Cecil error

	/Library/Frameworks/Mono.framework/Versions/Current/bin/mono /Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.5/mono-cil-strip.exe /Users/dahaligas/src/glad/gthy-pro-mobile/Core/Glad.iOS/obj/iPhone/Release/mtouch-cache/64/Build/System.Net.Http.Primitives.dll /Users/dahaligas/src/glad/gthy-pro-mobile/Core/Glad.iOS/bin/iPhone/Release/GladiOS.app/.monotouch-64/System.Net.Http.Primitives.dll
		Mono CIL Stripper
		
		Error: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
		Parameter name: index
		  at System.Collections.CollectionBase.System.Collections.IList.get_Item (System.Int32 index) [0x00022] in <12e050e5b3d34326a1b4e2e7624e75da>:0 
		  at Mono.Cecil.AssemblyNameReferenceCollection.get_Item (System.Int32 index) [0x00006] in <515b8343d4d0423f92114dba6b015690>:0 
		Stripping assembly /Users/dahaligas/src/glad/gthy-pro-mobile/Core/Glad.iOS/obj/iPhone/Release/mtouch-cache/64/Build/Plugin.ExternalMaps.Abstractions.dll
		/Library/Frameworks/Mono.framework/Versions/Current/bin/mono /Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.5/mono-cil-strip.exe /Users/dahaligas/src/glad/gthy-pro-mobile/Core/Glad.iOS/obj/iPhone/Release/mtouch-cache/64/Build/System.Xml.Linq.dll /Users/dahaligas/src/glad/gthy-pro-mobile/Core/Glad.iOS/bin/iPhone/Release/GladiOS.app/.monotouch-64/System.Xml.Linq.dll
		  at Mono.Cecil.ReflectionReader.GetExportedTypeScope (Mono.Cecil.Metadata.MetadataToken scope) [0x00043] in <515b8343d4d0423f92114dba6b015690>:0 
		  at Mono.Cecil.ReflectionReader.VisitExternTypeCollection (Mono.Cecil.ExternTypeCollection externs) [0x00089] in <515b8343d4d0423f92114dba6b015690>:0 
		  at Mono.Cecil.AggressiveReflectionReader.ReadExternTypes () [0x0000c] in <515b8343d4d0423f92114dba6b015690>:0 
		  at Mono.Cecil.AggressiveReflectionReader.VisitTypeDefinitionCollection (Mono.Cecil.TypeDefinitionCollection types) [0x0004f] in <515b8343d4d0423f92114dba6b015690>:0 
		  at Mono.Cecil.ReflectionReader.VisitModuleDefinition (Mono.Cecil.ModuleDefinition mod) [0x00007] in <515b8343d4d0423f92114dba6b015690>:0 
		  at Mono.Cecil.StructureReader.TerminateAssemblyDefinition (Mono.Cecil.AssemblyDefinition asm) [0x00034] in <515b8343d4d0423f92114dba6b015690>:0 
		  at Mono.Cecil.AssemblyDefinition.Accept (Mono.Cecil.IReflectionStructureVisitor visitor) [0x0001f] in <515b8343d4d0423f92114dba6b015690>:0 
		  at Mono.Cecil.AssemblyFactory.GetAssembly (Mono.Cecil.Binary.ImageReader irv, System.Boolean manifestOnly) [0x00014] in <515b8343d4d0423f92114dba6b015690>:0 
		  at Mono.Cecil.AssemblyFactory.GetAssembly (Mono.Cecil.Binary.ImageReader reader) [0x00000] in <515b8343d4d0423f92114dba6b015690>:0 
		  at Mono.Cecil.AssemblyFactory.GetAssembly (System.String file) [0x00006] in <515b8343d4d0423f92114dba6b015690>:0 
		  at Mono.CilStripper.Program.Main (System.String[] args) [0x00029] in <515b8343d4d0423f92114dba6b015690>:0
Comment 19 Sebastien Pouliot 2017-01-27 14:29:13 UTC
We now have a test case for this issue. Thanks!

*** This bug has been marked as a duplicate of bug 51805 ***
Comment 20 Philipp Sumi 2017-01-29 13:57:55 UTC
Can we ask you to post any (arbitratily dirty) workaround? We should urgently publish and this is blocking us :/
Comment 21 Sebastien Pouliot 2017-01-30 15:03:07 UTC
@Philipp you can

a) use the current XI stable (10.3.x) and not the beta/RC (10.4.x); or

b) disable IL stripping (using `--nostrip` in *additional mtouch arguments*) but it's global to the application, i.e. it will increase app size and will ship the IL for your applications (which can ease reverse engineering)
Comment 22 Michael Henke 2017-01-30 22:40:33 UTC
This has been resolved as duplicate but the duplicated bug is private... :(
Comment 23 Sebastien Pouliot 2017-01-30 22:43:28 UTC
@Michael it's now public (and should have been earlier, just a did not click hard enough on the checkbox)