Bug 59282 - Can't build with linked Dynamic Framework
Summary: Can't build with linked Dynamic Framework
Status: RESOLVED ANSWERED
Alias: None
Product: iOS
Classification: Xamarin
Component: Tools ()
Version: XI 10.99 (xcode9)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: 15.4
Assignee: Rolf Bjarne Kvinge [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2017-09-07 09:48 UTC by francois
Modified: 2017-09-08 23:17 UTC (History)
4 users (show)

Tags: Framework Dynamic IOS build link
Is this bug a regression?: Yes
Last known good build: 10.10.0.36


Attachments
Sample and logs (27.65 KB, application/zip)
2017-09-07 09:48 UTC, francois
Details
Sample with dynamic framework and nuget (48.87 KB, application/zip)
2017-09-08 13:43 UTC, francois
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 ANSWERED

Description francois 2017-09-07 09:48:21 UTC
Created attachment 24616 [details]
Sample and logs

Hello,

I met a blocking issue with the latest version of xamarin when trying to compile an application with a dynamic IOS framework.
I don't have this issue with an older version of Xamarin IOS with an older Mono Framework.
I put a sample project and all the logs and good/bad xamarin configuration in the attachment part.

In short, this is the error 

  MTOUCH : error MT0000: Unexpected error - Please file a bug report at http://bugzilla.xamarin.com
    System.IO.EndOfStreamException: Unable to read beyond the end of the stream.
      at System.IO.BinaryReader.FillBuffer (System.Int32 numBytes) [0x0007a] in /private/tmp/source-mono-d15-3/bockbuild-d15-3/profiles/mono-mac-xamarin/build-root/mono-x64/mcs/class/referencesource/mscorlib/system/io/binaryreader.cs:584 
      at System.IO.BinaryReader.ReadUInt32 () [0x00000] in /private/tmp/source-mono-d15-3/bockbuild-d15-3/profiles/mono-mac-xamarin/build-root/mono-x64/mcs/class/referencesource/mscorlib/system/io/binaryreader.cs:191 
      at Xamarin.MachO.ReadFile (System.IO.BinaryReader reader, System.String filename) [0x00001] in /Users/builder/data/lanes/4991/80b8487d/source/xamarin-macios/tools/common/MachO.cs:139 
      at Xamarin.MachO.ReadFile (System.String filename) [0x00014] in /Users/builder/data/lanes/4991/80b8487d/source/xamarin-macios/tools/common/MachO.cs:168 
      at Xamarin.MachO.SelectArchitectures (System.String filename, System.Collections.Generic.ICollection`1[T] abis) [0x00039] in /Users/builder/data/lanes/4991/80b8487d/source/xamarin-macios/tools/common/MachO.cs:206 
      at Xamarin.Bundler.Application.BuildBundle () [0x00716] in /Users/builder/data/lanes/4991/80b8487d/source/xamarin-macios/tools/mtouch/Application.cs:1624 
      at Xamarin.Bundler.Application.BuildAll () [0x0009c] in /Users/builder/data/lanes/4991/80b8487d/source/xamarin-macios/tools/mtouch/Application.cs:777 
      at Xamarin.Bundler.Driver.Main2 (System.String[] args) [0x00481] in /Users/builder/data/lanes/4991/80b8487d/source/xamarin-macios/tools/mtouch/mtouch.cs:1420 
      at Xamarin.Bundler.Driver.Main (System.String[] args) [0x0000f] in /Users/builder/data/lanes/4991/80b8487d/source/xamarin-macios/tools/mtouch/mtouch.cs:945
Comment 1 John Miller [MSFT] 2017-09-07 14:18:50 UTC
I am able to reproduce this with 10.12.0.20 when building for a device. Simulator builds complete successfully. 

Regression Check: Seems to be a regression

BAD: 10.12.0.20
GOOD: 10.10.0.36
GOOD: 10.8.0.175
Comment 2 francois 2017-09-07 15:11:00 UTC
For the simulator, 
The Framework in the sample is in arm64 and apparently Xamarin with simulator ignore the Framework even it's not the same arch.
Another issue, but i don't really care.
Comment 3 Rolf Bjarne Kvinge [MSFT] 2017-09-08 13:03:34 UTC
You're copying the framework to the app by marking the files as bundle resources, and then you're passing --framework:<path> to mtouch (in the project's iOS Build options), where the path to the framework is to the copied framework inside the app bundle.

This is problematic, because --framework will copy the framework into the app bundle too.

Since the framework is already in the app bundle, it ends up creating a zero-length file when copying the framework to the same location, which is bad.

Do this instead:

* Remove the TestBug.framework files from the project.
* Pass --framework:${ProjectDir}/Resources/Frameworks/TestBug.framework to mtouch

Alternatively you can:

* Remove the TestBug.framework files from the project.
* Remove the --framework:<path> argument from mtouch's arguments.
* Re-add the TestBug.framework to the project as a native reference (right-click the project -> Add Native Reference -> Navigate to TestBug.framework and select it).
Comment 4 francois 2017-09-08 13:17:54 UTC
Ok, I will try,
What if, I'm using the framework from a NuGet instead of inside the project.
I will do the test.

I think it's still a regression because this issue was not here before.
So why close this issue?
Comment 5 francois 2017-09-08 13:40:47 UTC
Ok, it's work
Even inside a nuget.
I put my sample with nuget in the attachment.

Kind of tricky for the solution, it's not obvious.

Thanks
Comment 6 francois 2017-09-08 13:43:39 UTC
Created attachment 24651 [details]
Sample with dynamic framework and nuget

This a sample for how to use IOS dynamic Framework inside a binding project+nuget and a simple IOS project
Comment 7 Rolf Bjarne Kvinge [MSFT] 2017-09-08 23:17:34 UTC
Yes, that's correct, for a binding project you should also use a Native Reference, which makes sure the framework is bundled into the binding assembly (and correctly extracted when built with the executable project).