Bug 58826 - MMP does not handle platform assembly swapping when a dependency using XM comes first in 32-bit
Summary: MMP does not handle platform assembly swapping when a dependency using XM com...
Status: VERIFIED FIXED
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: 3.8.0 (d15-4)
Hardware: PC Mac OS
: High normal
Target Milestone: 15.5
Assignee: Chris Hamons
URL:
Depends on:
Blocks:
 
Reported: 2017-08-16 21:42 UTC by Chris Hamons
Modified: 2017-12-26 11:16 UTC (History)
3 users (show)

Tags:
Is this bug a regression?: No
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:
VERIFIED FIXED

Description Chris Hamons 2017-08-16 21:42:32 UTC
Steps to reproduce:

1) Create new XM Modern App
2) Add a reference to a nuget using Xamarin.Mac. Xamarin.Forms.2.3.5.256-pre6 for example)
3) Swap to i386
4) Build and run
5) Crash

Native type size mismatch between Xamarin.Mac.dll and the executing architecture. Xamarin.Mac.dll was built for 64-bit, while the current process is 32-bit.
Stacktrace:

  at <unknown> <0xffffffff>
  at (wrapper managed-to-native) object.wrapper_native_0xa2770 () <0x00012>
  at ObjCRuntime.Runtime.EnsureInitialized () [0x0004a] in /Users/donblas/Programming/macios/cycle9/xamarin-macios/src/ObjCRuntime/Runtime.mac.cs:118
  at AppKit.NSApplication.Init () [0x00017] in /Users/donblas/Programming/macios/cycle9/xamarin-macios/src/AppKit/NSApplication.cs:56
  at Mobile32.MainClass.Main (string[]) [0x00001] in /Users/donblas/Projects/Mobile32/Main.cs:9
  at (wrapper runtime-invoke) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) [0x00051] in <2076c811a8514765bf1d226d27b7acb5>:0


This is because we first call SwapOutReferenceAssembly in driver.cs with the reference, not file name, don't swap it out. And then later do.

This is likely always been broken, but since we fall back to the "reference", which is x86_64, we never noticed. i386 is not common.
Comment 2 Chris Hamons 2017-08-17 19:28:22 UTC
https://github.com/xamarin/xamarin-macios/pull/2503
Comment 4 Chris Hamons 2017-08-24 21:05:29 UTC
This is fixed in master and will be released in the 15.5 release.

Until then the simplest work around would be to use a post-build target (https://github.com/xamarin/mac-samples/tree/master/UseMSBuildToCopyFilesToBundleExample) to a 32-bit Xamarin.Mac from

/Library/Frameworks/Xamarin.Mac.framework/Versions/Current/lib/i386/{full,mobile}/Xamarin.Mac.dll

into your final bundle. In this application, it would be the Full, since it is using the Full (Not Mobile/Modern) version.