This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 44518 - Error while loading assemblies. Buffer cannot be null
Summary: Error while loading assemblies. Buffer cannot be null
Status: RESOLVED DUPLICATE of bug 44122
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools (show other bugs)
Version: XI 10.0 (iOS10)
Hardware: Macintosh Mac OS
: Normal major
Target Milestone: (C9)
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2016-09-20 10:27 UTC by Dmitry Adodin
Modified: 2016-09-26 13:15 UTC (History)
5 users (show)

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


Attachments
Moving .a to the main app native references (76.56 KB, image/png)
2016-09-22 16:01 UTC, Sebastien Pouliot
Details

Description Dmitry Adodin 2016-09-20 10:27:58 UTC
# Steps to reproduce
https://forums.xamarin.com/discussion/77744/error-while-loading-assemblies-buffer-cannot-be-null

# Expected behavior


# Actual behavior


# Supplemental info (logs, images, videos)


# Test environment (full version information)
		Xamarin Studio Business
Version 6.1 (build 5441)
Installation UUID: bfbc4269-9411-4b1d-a9a9-c1f09ffab2be
Runtime:
	Mono 4.6.0 (mono-4.6.0-branch/746756c) (64-bit)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 406000245

NuGet
Version: 3.4.3.0

Xamarin.Profiler
Not Installed

Xamarin.Android
Not Installed

Xamarin Android Player
Not Installed

Apple Developer Tools
Xcode 8.0 (11246)
Build 8A218a

Xamarin.Mac
Version: 2.10.0.99 (Xamarin Business)

Xamarin.iOS
Version: 10.0.0.6 (Xamarin Business)
Hash: 6c3fee4
Branch: xcode8
Build date: 2016-09-09 13:01:32-0400

Build Information
Release ID: 601005441
Git revision: 68292d1ab289911c815ddc715dd7cc29a9752f9f
Build date: 2016-09-09 04:43:23-04
Xamarin addins: ed25d008672663eeb9db55f1ccecb3c24d2fd3b2
Build lane: monodevelop-lion-cycle8

Operating System
Mac OS X 10.11.6
Darwin Ivans-Mac-mini 15.6.0 Darwin Kernel Version 15.6.0
    Mon Aug 29 20:21:34 PDT 2016
    root:xnu-3248.60.11~1/RELEASE_X86_64 x86_64
Comment 1 Alex Soto 2016-09-20 19:24:55 UTC
Hello Dimitry 

Thanks for contacting us, is there any way you could provide us a test case? It does not necessarily needs to be your app project, it can be the binding project plus a fake app project just using a little of the api of the binding so we can reproduce and fix the issue.

Cheers!
Comment 2 Dmitry Adodin 2016-09-21 03:20:57 UTC
OK. Here is stacktrace 

		Tool /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch execution started with arguments: --cache /Users/developer/Projects/LinkingTest/LinkingTest/obj/iPhone/Debug/mtouch-cache --dev /Users/developer/Projects/LinkingTest/LinkingTest/bin/iPhone/Debug/LinkingTest.app --executable LinkingTest --fastdev --debug --profiling --linksdkonly --sdkroot /Applications/Xcode.app/Contents/Developer --sdk 10.0 --targetver 8.0 --aot-options=-O=float32 --http-message-handler=HttpClientHandler --tls-provider=default --abi=armv7,arm64 --symbollist /Users/developer/Projects/LinkingTest/LinkingTest/obj/iPhone/Debug/mtouch-symbols.list --dsym=no -vvvv --cxx --registrar:static --gcc_flags "-L/Users/developer/Projects/LinkingTest/LinkingTest/../RMSDKWrapper -dead_strip -lstdc++ -lstdc++.6.0.9 -lpthread -lsqlite3 -lxml2 -ObjC -ladept-iOS -lxml-iOS -lz -lcurl -lssl -lcrypto -ldp-iOS -lePub3-iOS -L/usr/lib -I/usr/include/libxml2" -r /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/System.dll -r /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/System.Xml.dll -r /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/System.Core.dll -r /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/Xamarin.iOS.dll -r /Users/developer/Projects/LinkingTest/RMSDKWrapper/bin/Debug/RMSDKWrapper.dll -r /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS/mscorlib.dll -r /Users/developer/Projects/LinkingTest/RMSDKWrapper/bin/Debug/RMSDKWrapper.dll --target-framework Xamarin.iOS,v1.0 /Users/developer/Projects/LinkingTest/LinkingTest/bin/iPhone/Debug//LinkingTest.exe 
		Using Xcode 8.0 found in /Applications/Xcode.app/Contents/Developer
		Xamarin.iOS 10.0.0.6 (xcode8: 6c3fee4) using framework: /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.0.sdk
		A full rebuild will be performed because the cache is either incomplete or entirely missing.
MTOUCH: error MT0009: Error while loading assemblies: /Users/developer/Projects/LinkingTest/RMSDKWrapper/bin/Debug/RMSDKWrapper.dll
		--- inner exception
		System.ArgumentNullException: Buffer cannot be null.
		Parameter name: buffer
		  at System.IO.BinaryReader.Read (System.Byte[] buffer, System.Int32 index, System.Int32 count) [0x0007e] in /private/tmp/source-mono-4.6.0/bockbuild-xamarin/profiles/mono-mac-xamarin/build-root/mono-x86/mcs/class/referencesource/mscorlib/system/io/binaryreader.cs:513 
		  at Mono.Cecil.PE.ImageReader.ReadSectionData (Mono.Cecil.PE.Section section) [0x00039] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/external/cecil/Mono.Cecil.PE/ImageReader.cs:299 
		  at Mono.Cecil.PE.ImageReader.ReadSections (System.UInt16 count) [0x0005c] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/external/cecil/Mono.Cecil.PE/ImageReader.cs:283 
		  at Mono.Cecil.PE.ImageReader.ReadImage () [0x00090] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/external/cecil/Mono.Cecil.PE/ImageReader.cs:104 
		  at Mono.Cecil.PE.ImageReader.ReadImageFrom (System.IO.Stream stream) [0x0000a] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/external/cecil/Mono.Cecil.PE/ImageReader.cs:673 
		  at Mono.Cecil.ModuleDefinition.ReadModule (System.IO.Stream stream, Mono.Cecil.ReaderParameters parameters) [0x0002a] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/external/cecil/Mono.Cecil/ModuleDefinition.cs:981 
		  at Mono.Cecil.ModuleDefinition.ReadModule (System.String fileName, Mono.Cecil.ReaderParameters parameters) [0x0000e] in /Users/builder/data/lanes/3426/6c3fee4d/source/xamarin-macios/external/cecil/Mono.Cecil/ModuleDefinition.cs:963 
		  at MonoTouch.Tuner.MonoTouchResolver.Load (System.String fileName) [0x00077] in <86a99508958c45bc8a05d21e3b49a458>:0 
		---
		  at MonoTouch.Tuner.MonoTouchResolver.Load (System.String fileName) [0x000a7] in <86a99508958c45bc8a05d21e3b49a458>:0 
		  at MonoTouch.Tuner.MonoTouchManifestResolver.Load (System.String file) [0x00040] in <86a99508958c45bc8a05d21e3b49a458>:0 
		  at Xamarin.Bundler.Target.Initialize (System.Boolean show_warnings) [0x00062] in <86a99508958c45bc8a05d21e3b49a458>:0 
		  at Xamarin.Bundler.Application.Initialize () [0x0053b] in <86a99508958c45bc8a05d21e3b49a458>:0 
		  at Xamarin.Bundler.Application.Build () [0x00034] in <86a99508958c45bc8a05d21e3b49a458>:0 
		  at Xamarin.Bundler.Driver.Main2 (System.String[] args) [0x01c6c] in <86a99508958c45bc8a05d21e3b49a458>:0 
		  at Xamarin.Bundler.Driver.Main (System.String[] args) [0x0000c] in <86a99508958c45bc8a05d21e3b49a458>:0 
	Task "MTouch" execution -- FAILED
Comment 3 Alex Soto 2016-09-21 03:23:08 UTC
Hello Dmitry

One thing I forgot to mention, please add

-v -v -v -v

To "Additional mtouch arguments" inside your project settings > Build > iOS build

So we get a more detailed build logs
Comment 4 Dmitry Adodin 2016-09-21 03:51:53 UTC
there is -vvvv 

and here is test proj
https://1drv.ms/u/s!AvbxFZbqrsQY5GHBe6gB7oz9lknA
Comment 5 Sebastien Pouliot 2016-09-21 12:22:00 UTC
@Dmitry thanks for providing a test case, I'll be looking into this asap.
Comment 6 Sebastien Pouliot 2016-09-21 12:45:24 UTC
I do get the same error, thanks!

	MTOUCH: error MT1010: Could not load the assembly '/Users/poupou/Downloads/LinkingTest/LinkingTest/obj/iPhoneSimulator/Debug/mtouch-cache/Link/RMSDKWrapper.dll': Error while loading assemblies: /Users/poupou/Downloads/LinkingTest/LinkingTest/obj/iPhoneSimulator/Debug/mtouch-cache/Link/RMSDKWrapper.dll
	MTOUCH: error MT0009: Error while loading assemblies: /Users/poupou/Downloads/LinkingTest/LinkingTest/obj/iPhoneSimulator/Debug/mtouch-cache/Link/RMSDKWrapper.dll
Comment 7 Sebastien Pouliot 2016-09-21 13:30:16 UTC
RMSDKWrapper.dll is quite large, at 1,302,935,040 bytes. Ideally it would be broken down as several dependencies (that would help the build performance).

If I run the build with Mono 4.4 it does works , but it fails with Mono 4.6.

Can you try:

1. using mono 4.4.x;

or

2. edit /Library/Frameworks/Xamarin.iOS.framework//Versions/Current/bin/mtouch

and change `mono` to `mono64` (the 64 bits version of mono).


In both case I got farther in the compilation process and the errors seems legit (and likely related to the test case).
Comment 8 Dmitry Adodin 2016-09-21 14:27:37 UTC
Rollback to August Xamarin Build helped, but it's not good on perspective.

Most of .a files are prebuild third-party libs (some of them 300-400mb) used by Adobe Reader Mobile SDK (RMSDK) so I have no idea, how to separate them.
Comment 9 Sebastien Pouliot 2016-09-21 19:06:36 UTC
@Dmitry it's a workaround, not the fix :) but you should be able to _only_ downgrade mono (and not the rest of the tooling).

As for RMSDKWrapper.dll I did not mean to split the .a (they are not yours and should not be modified) but to move most (all but librmsdk_wrapper2_iOS.a) outside the binding project. That results in a .dll that's only 25MB (and will speed up your builds).

Native references in a binding projects all gets embedded in the .dll. That's quite handy for sharing a self-contained binary component but it was not meant to include all dependencies.

The other static libraries are still needed and you can use native references on your main project (without them being embedded). The end result will be the same, but this is less resource intensive.
Comment 10 Dmitry Adodin 2016-09-22 03:29:27 UTC
Oh thanks, that should be somewhere in tutorials, but them are too simple.

I'll try that again. First time I wasn't able to compile them all together without adding to binding, may be now I will.
Comment 11 Dmitry Adodin 2016-09-22 03:29:57 UTC
btw, is status NEEDINFO correct?
Comment 12 Sebastien Pouliot 2016-09-22 15:14:52 UTC
NEEDINFO, yes until you confirm the workaround works for you. That will assure me* there's not other errors from your application and the the full extent of the issue is known. Sometimes the test case only expose half of the problem :)

* your sample launch on device for me (and the throw an ArgumentNullException which is expected as null is provided).
Comment 13 Dmitry Adodin 2016-09-22 15:41:33 UTC
workaround with downgrading works, thx.

what about shrinking library, I definitely do something wrong.
Comment 14 Sebastien Pouliot 2016-09-22 16:01:21 UTC
Created attachment 17682 [details]
Moving .a to the main app native references

This is how I re-structured your test case locally.

Only the .a being bound is in the binding project, all other dependencies are directly added to the main app.
Comment 15 Dmitry Adodin 2016-09-22 16:11:19 UTC
Oh, thx!
Comment 16 Sebastien Pouliot 2016-09-23 15:47:32 UTC
PR (master) https://github.com/xamarin/xamarin-macios/pull/887

A workaround is to edit the mtouch script

> /Library/Frameworks/Xamarin.iOS.framework/Versions/Current/bin/mtouch


and change `mono` to `mono64`

*** This bug has been marked as a duplicate of bug 44122 ***
Comment 17 Sergey 2016-09-26 09:29:19 UTC
I am not authorised to see the bug 44122, but am interested in seeing the resolution. Should I post a new bug?
Comment 18 Rolf Bjarne Kvinge [MSFT] 2016-09-26 09:34:09 UTC
@Sergey, Sebastien posted the resolution of bug 44122 here in comment #16.
Comment 19 Sergey 2016-09-26 13:00:44 UTC
@Rolf, I thought it was a temporary workaround - does that mean that a real fix will only be available with a new update of the Mono?
Comment 20 Rolf Bjarne Kvinge [MSFT] 2016-09-26 13:04:13 UTC
@Sergey, it is the actual fix, and it will be included in the next version of Xamarin.iOS. If you don't want to wait, you can implement the fix yourself (since it's just modifying a text file).

For reference here's our fix: https://github.com/xamarin/xamarin-macios/commit/eb91e692a675d44ac43d8e326049e250e21473b4
Comment 21 Sergey 2016-09-26 13:15:18 UTC
@Rolf Thank you, Rolf, got it.

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