Bug 18332 - error merging Mono Runtime into app bundle for Xamarin.Mac at .NET 4.5
Summary: error merging Mono Runtime into app bundle for Xamarin.Mac at .NET 4.5
Status: RESOLVED FIXED
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: mmp ()
Version: 1.6.27
Hardware: PC Mac OS
: --- normal
Target Milestone: 1.8.0
Assignee: Aaron Bockover [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2014-03-12 19:05 UTC by Jon Goldberger [MSFT]
Modified: 2014-03-21 14:24 UTC (History)
3 users (show)

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

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 FIXED

Comment 1 Jon Goldberger [MSFT] 2014-03-12 19:06:19 UTC
From desk case: 
Earlier I sent an email on this subject, I have more insight now. I need
help on this as it is now blocking release - or some sort of release. :)

I have been using .NET 4.5 in Xamarin Studio with portable libraries and a
Xamarin.Mac project. When the Xamarin.Mac project is set to .NET 4.5 and
Microsoft Async is added via nuget, compile in Debug will succeed but
Release/AppStore will fail with

error MM2002: Failed to resolve assembly: 'System.Threading.Tasks,
> Version=1.5.11.0,


In this case, it is unnecessary to add the dlls (System.Threading.Tasks and
System.Runtime) from BCL because they are already in .NET 4.5. If you
switch to .NET 4.0 it will work, but I have a lot of code already in .NET
4.5 that cannot be reversed because of other dependencies.

Somehow, BCL is not recognizing the Xamarin.Mac .NET 4.5 project as .NET
4.5 and still requiring the dlls.

To replicate:
1. Create a new Xamarin.Mac project
2. Set it to .NET 4.5
3. Use nuget to fetch Microsoft Async (notice correctly it does not pull in
System.Threading.Tasks or System.Runtime)
4. Switch to Release
5. Compile

Perhaps there is something I can do in the csproj to tell BCL that this is
.NET 4.5. Any help would be much appreciated.
Comment 2 Jon Goldberger [MSFT] 2014-03-13 16:25:30 UTC
More info:

1. Create an empty solution in Xamarin Studio

2. Create a Portable Library (take the default profile 136), call it
xxx.Core

3. Create a Xamarin.Mac project (take the default .NET 4.5), call it
xxx.XamMac

4. In Core, rename MyClass.cs to MyEventArgs.cs, make it inherit from
EventArgs - this creates a class that is dependent on System (and normally
inside of System.Runtime.dll in Windows)

public class MyEventArgs : EventArgs
{
public MyEventArgs ()
{
}
}

5. In XamMac, add the following to AppDelegate.cs

public AppDelegate ()
{
var args = new MyEventArgs ();
var bargs = args;
}

6. Make sure that xxx.Core is added to the References so that MyEventArgs
resolves

7. Compile in Debug, it works

8. Compile in Release, it works

9. Now change xxx.Core to Profile 78 (.NET 4.5, etc.)

10. Change XamMac to .NET 4.5

11. Compile in Release, it fails with

error MM2002: Failed to resolve assembly: 'System.Runtime


I think there is something wrong with .NET 4.5 in Xamarin.Mac.
Unfortunately I'm nearing a product release and I can't really back up into
.NET 4.0 without doing a lot more work. I would be so appreciative if a
solution can be found.

I'm in Mountain View and could come up to SF if that helps.
Comment 4 Jon Goldberger [MSFT] 2014-03-13 16:31:25 UTC
PS, the above (comment #2) compiles if Linker is set to "Don't Link"
Comment 5 Aaron Bockover [MSFT] 2014-03-13 17:52:12 UTC
This is the error I get with mmp trying to link:

/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/bin/mmp "-minos=10.6" --sdkroot "/Applications/Xcode.app/Contents/Developer" -o "/Users/aaron/Projects/pcltest/macpcl/bin/Debug" -n "macpcl" --profile "4.5" --debug -a "/Users/aaron/Projects/pcltest/pcltest/bin/Debug/pcltest.dll" -a "/Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/4.5/System.dll" -a "/Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/4.5/System.Xml.dll" -a "/Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/4.5/System.Core.dll" -a "/Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/4.5/System.Xml.Linq.dll" -a "/Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/4.5/System.Drawing.dll" -a "/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/XamMac.dll" -a "/Library/Frameworks/Mono.framework/Versions/3.4.0/lib/mono/4.5/System.Core.dll" "/Users/aaron/Projects/pcltest/macpcl/bin/Debug/macpcl.exe"
error MM2002: Failed to resolve assembly: 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'
Comment 6 Tim Uy 2014-03-14 11:01:15 UTC
Aaron, it seems that there is something incomplete in the implementation of PCLs for .NET 4.5. When the .NET version is set to 4.0, this does not happen. Unfortunately this is now blocking for us as we have a number of components (portable) that are using .NET 4.5.
Comment 7 Aaron Bockover [MSFT] 2014-03-14 15:42:37 UTC
This may not be a bug specific to Xamarin.Mac. I'm wondering if you can provide an isolated test case that reproduces the problem but using just a plain console C# project? If we can reproduce it with Xamarin.Mac out of the way, then the fix should probably be pretty straight forward in the Mono runtime.
Comment 8 Aaron Bockover [MSFT] 2014-03-14 16:18:52 UTC
Oh, nevermind. I forgot that this is specific to when assemblies are being linked.
Comment 9 Aaron Bockover [MSFT] 2014-03-14 16:49:36 UTC
Alright, so this looks like it's a bug in Xamarin Studio - it's not passing the PCL/facade assembly references to the linker (mmp).

We've got enough to go on for a real fix, but to un-block you immediately, you can fix this within your project.

There are two options, both of which apply to your main Xamarin.Mac project (the one with "Mac OS X Packaging" under project options):

(a) using the regular references support in XS, add a new reference from the ".NET Assembly" tab. Navigate to -a /Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.5/Facades, and select the necessary assembly (System.Runtime.dll for starters).

-OR-

(b) under "Mac OS X Packaging", navigate to the advanced tab, and add "-a /Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.5/Facades/System.Runtime.dll" to the "Advanced Mono Bundling Options" field. For each assembly you add, ensure you have specified the full absolute path and the path is prefixed with the -a flag.

For the repro case detailed on this bug, you only need to add the System.Runtime reference. Your application may need more, but the error from mmp will tell you which one you need to add. Keep adding until you get a working build using one of the methods above.
Comment 10 Aaron Bockover [MSFT] 2014-03-14 17:22:45 UTC
I've now fixed this for the upcoming Xamarin.Mac release.
Comment 11 Tim Uy 2014-03-21 14:15:46 UTC
Thank you so much Aaron. When is the next release? 

In the meantime, I am working on method (a). For some reason method (b) did not really work. I do have a small request, that the Edit References dialog remember the last location in Recently Used. It seems to be always blank for me so I have to re-traverse the path.
Comment 12 Tim Uy 2014-03-21 14:19:58 UTC
oh oh - I've been adding dlls from Facades - I added Threading.Tasks, then Runtime, then ObjectModel - but now it wants PresentationCore???  strange - it shouldn't need PresentationCore at all (it certainly doesn't need it in Debug)
Comment 13 Tim Uy 2014-03-21 14:23:50 UTC
I double-checked and everything still works in Debug. Here is the error on Release. Note Facades near the bottom

error MM2002: Failed to resolve assembly: 'PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

--
Merging Mono Runtime into app bundle
/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/bin/mmp "-minos=10.6" --sdkroot "/Applications/Xcode.app/Contents/Developer" -o "/Loqu8/Projects/sapatos/src/Sapatos/Sapatos.XamMac/bin/Release" -n "Sapatos.XamMac" --profile "4.5" -a "/Loqu8/Projects/sapatos/src/Sapatos/Sapatos.Core/bin/Release/Sapatos.Core.dll" -a "/Loqu8/Projects/sapatos/src/Loqu8/Loqu8.Capture.XamMac/bin/Release/Loqu8.Capture.XamMac.dll" -a "/Loqu8/Projects/sapatos/src/Loqu8/Loqu8.Speech.XamMac/bin/Release/Loqu8.Speech.XamMac.dll" -a "/Library/Frameworks/Mono.framework/Versions/3.2.6/lib/mono/4.5/System.dll" -a "/Library/Frameworks/Mono.framework/Versions/3.2.6/lib/mono/4.5/System.Xml.dll" -a "/Library/Frameworks/Mono.framework/Versions/3.2.6/lib/mono/4.5/System.Core.dll" -a "/Library/Frameworks/Mono.framework/Versions/3.2.6/lib/mono/4.5/System.Xml.Linq.dll" -a "/Library/Frameworks/Mono.framework/Versions/3.2.6/lib/mono/4.5/System.Drawing.dll" -a "/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/mono/XamMac.dll" -a "/Library/Frameworks/Mono.framework/Versions/3.2.6/lib/mono/4.5/System.Net.dll" -a "/Library/Frameworks/Mono.framework/Versions/3.2.6/lib/mono/4.5/System.Net.Http.dll" -a "/Library/Frameworks/Mono.framework/Versions/3.2.6/lib/mono/4.5/System.Net.Http.WebRequest.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/Microsoft.Bcl.Async.1.0.165/lib/net45/Microsoft.Threading.Tasks.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/Microsoft.Bcl.Async.1.0.165/lib/net45/Microsoft.Threading.Tasks.Extensions.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/CsvHelper.2.4.8-beta1/lib/net40-client/CsvHelper.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/Microsoft.Net.Http.2.2.18/lib/net45/System.Net.Http.Primitives.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/Microsoft.Net.Http.2.2.18/lib/net45/System.Net.Http.Extensions.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/Loqu8.KVC.XamMac.1.1.18/lib/net45/Loqu8.KVC.XamMac.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/Splat.1.2.1/lib/Net45/Splat.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/MvvmCross.Community.Plugin.Sqlite.XamMac.3.1.40-beta1/lib/net45/Cirrious.MvvmCross.Community.Plugins.Sqlite.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/MvvmCross.Community.Plugin.Sqlite.XamMac.3.1.40-beta1/lib/net45/Cirrious.MvvmCross.Community.Plugins.Sqlite.XamMac.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/Loqu8.MvvmCross.Plugins.Cryptography.XamMac.3.1.59-beta1/lib/net45/Loqu8.MvvmCross.Plugins.Cryptography.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/Loqu8.MvvmCross.Plugins.Cryptography.XamMac.3.1.59-beta1/lib/net45/Loqu8.MvvmCross.Plugins.Cryptography.XamMac.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/MvvmCross.HotTuna.CrossCore.XamMac.3.1.176-beta5/lib/net45/Cirrious.CrossCore.XamMac.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/MvvmCross.HotTuna.CrossCore.XamMac.3.1.176-beta5/lib/net45/Cirrious.MvvmCross.Binding.XamMac.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/MvvmCross.HotTuna.CrossCore.XamMac.3.1.176-beta5/lib/net45/Cirrious.CrossCore.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/MvvmCross.HotTuna.CrossCore.XamMac.3.1.176-beta5/lib/net45/Cirrious.MvvmCross.Binding.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/MvvmCross.HotTuna.CrossCore.XamMac.3.1.176-beta5/lib/net45/Cirrious.MvvmCross.Localization.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/MvvmCross.HotTuna.MvvmCrossLibraries.XamMac.3.1.176-beta5/lib/net45/Cirrious.MvvmCross.XamMac.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/MvvmCross.HotTuna.MvvmCrossLibraries.XamMac.3.1.176-beta5/lib/net45/Cirrious.MvvmCross.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/Loqu8.MvvmCross.Plugins.IO.XamMac.3.1.59-beta1/lib/net45/Loqu8.MvvmCross.Plugins.IO.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/Loqu8.MvvmCross.Plugins.IO.XamMac.3.1.59-beta1/lib/net45/Loqu8.MvvmCross.Plugins.IO.XamMac.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/Loqu8.MvvmCross.Plugins.Stopwatch.XamMac.3.1.59-beta1/lib/net45/Loqu8.MvvmCross.Plugins.Stopwatch.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/Loqu8.MvvmCross.Plugins.Stopwatch.XamMac.3.1.59-beta1/lib/net45/Loqu8.MvvmCross.Plugins.Stopwatch.XamMac.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/MvvmCross.PortableSupport.Mac.3.1.176-beta5/lib/net45/System.Windows.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/Loqu8.Capture.XamMac.8.0.39-beta/lib/net45/Loqu8.Capture.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/Loqu8.Common.XamMac.8.0.39-beta/lib/net45/Loqu8.Common.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/Loqu8.Dict.CE.XamMac.8.0.39-beta/lib/net45/Loqu8.Dict.CE.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/Loqu8.Dict.XamMac.8.0.39-beta/lib/net45/Loqu8.Dict.dll" -a "/Loqu8/Projects/sapatos/src/slns/sapatos_xs/packages/Loqu8.Speech.XamMac.8.0.39-beta/lib/net45/Loqu8.Speech.dll" -a "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.5/Facades/System.Threading.Tasks.dll" -a "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.5/Facades/System.Runtime.dll" -a "/Library/Frameworks/Mono.framework/Versions/Current/lib/mono/4.5/Facades/System.ObjectModel.dll" -a "/Library/Frameworks/Mono.framework/Versions/3.2.6/lib/mono/4.5/System.Core.dll" "/Loqu8/Projects/sapatos/src/Sapatos/Sapatos.XamMac/bin/Release/Sapatos.XamMac.exe"
error MM2002: Failed to resolve assembly: 'PresentationCore, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
mmp exited with code 1
Comment 14 Tim Uy 2014-03-21 14:24:50 UTC
the latter is probably a problem with Splat, I'll have to look at it again