Bug 4530 - Bad references to .exe between projects
Summary: Bad references to .exe between projects
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: iOS add-in ()
Version: Trunk
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Jeffrey Stedfast
Depends on:
Blocks: 4468
  Show dependency tree
Reported: 2012-04-19 13:57 UTC by Sebastien Pouliot
Modified: 2012-04-23 08:40 UTC (History)
2 users (show)

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:

Description Sebastien Pouliot 2012-04-19 13:57:04 UTC
Note: This is an uncommon scenario (see bug #4468) but can occurs if you want to unit tests code inside another project's main .exe.

When a reference is made between project "App" and project "App2" the reference is made to the .exe inside the .app directory and _not_ the one what MD's smcs compilation produce, e.g.

/Developer/MonoTouch/usr/bin/smcs /noconfig "/out:/Developer/MonoTouch/Source/monotouch/tests/monotouch-test/bin/iPhone/Release/monotouchtest.exe" "/r:/Developer/MonoTouch/usr/lib/mono/2.1/System.dll" "/r:/Developer/MonoTouch/usr/lib/mono/2.1/System.Xml.dll" "/r:/Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll" "/r:/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll" "/r:/Developer/MonoTouch/usr/lib/mono/2.1/MonoTouch.NUnitLite.dll" /nologo /warn:4 /optimize- /codepage:utf8 /t:exe 

while MonoDevelop will call `mtouch` with a command-line that looks like:

/Developer/MonoTouch/usr/bin/mtouch -sdkroot "/Developer" -v --nomanifest --nosign -dev "/Developer/MonoTouch/Source/monotouch/tests/mscorlib-test/bin/iPhone/Release/mscorlibtest.app" -r "/Developer/MonoTouch/Source/monotouch/tests/monotouch-test/bin/iPhone/Release/monotouchtest.app/monotouchtest.exe" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.Xml.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/System.Core.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/monotouch.dll" -r "/Developer/MonoTouch/usr/lib/mono/2.1/MonoTouch.NUnitLite.dll" -linksdkonly -sdk "5.0" "-v" "-v" "/Developer/MonoTouch/Source/monotouch/tests/mscorlib-test/bin/iPhone/Release/mscorlibtest.exe"

This fails, for Release builds, since the .exe inside the ".app" directory will be *stripped* of all it's IL code (at the end of it's build). 

This means the AOT compiler (for the "real" main app .exe) will be given garbage (invalid IL since all methods simply have a RET instruction even if they return something). E.g.

MONO_PATH=/Developer/MonoTouch/Source/monotouch/tests/mscorlib-test/bin/iPhone/Release/mscorlibtest.app /Developer/MonoTouch/usr/bin/arm-darwin-mono --aot=mtriple=armv6-darwin,full,static,asmonly,nodebug,outfile=/var/folders/fI/fIDK1klFH6yDR8NRb2cq-++++TI/-Tmp-/tmp2ca377df.tmp/monotouchtest.exe.6.s "/Developer/MonoTouch/Source/monotouch/tests/mscorlib-test/bin/iPhone/Release/mscorlibtest.app/monotouchtest.exe"
Mono Ahead of Time compiler - compiling assembly /Developer/MonoTouch/Source/monotouch/tests/mscorlib-test/bin/iPhone/Release/mscorlibtest.app/monotouchtest.exe
Code: 39304 Info: 1211 Ex Info: 1634 Unwind Info: 1229 Class Info: 2223 PLT: 108 GOT Info: 3289 GOT: 740 Offsets: 2251
Output file: '/var/folders/fI/fIDK1klFH6yDR8NRb2cq-++++TI/-Tmp-/tmp2ca377df.tmp/monotouchtest.exe.6.s'.
Linking symbol: '_mono_aot_module_monotouchtest_info'.
Compiled 493 out of 548 methods (89%)
Methods without GOT slots: 418 (76%)
Direct calls: 0 (100%)
JIT time: 28 ms, Generation time: 26 ms, Assembly+Link time: 0 ms.

^ the hint is the "Compiled 493 out of 548 methods (89%)"

The solution is to provide, as a reference, the .exe that MD asked SMCS to produce (and not the final one produced later by mtouch).