Bug 14969 - Bug in compiler assembly resolution on MonoAndroid
Summary: Bug in compiler assembly resolution on MonoAndroid
Status: RESOLVED INVALID
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.8.x
Hardware: PC Mac OS
: --- normal
Target Milestone: ---
Assignee: Mikayla Hutchinson [MSFT]
URL:
Depends on:
Blocks:
 
Reported: 2013-09-24 18:42 UTC by Jon Goldberger [MSFT]
Modified: 2013-09-27 20:14 UTC (History)
2 users (show)

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


Attachments
Log files (6.67 KB, application/zip)
2013-09-24 19:26 UTC, Jon Goldberger [MSFT]
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 INVALID

Description Jon Goldberger [MSFT] 2013-09-24 18:42:54 UTC
On the Alpha version of Xamarin.MonoAndroid, I can no longer build my
project, due to what appears to be assembly resolution issues (skip to the
last paragraph for the bug).

Here's my version info:
https://gist.github.com/paulcbetts/0701cb864c25d0a46753

Here's how to repro:

1. git clone https://github.com/github/akavache
2. Open in Xamarin Studio, switch to Release build
3. Build

You'll end up with:

: error CS1705: Assembly `Akavache, Version=3.0.2.0, Culture=neutral,
PublicKeyToken=null' references `System.Reactive.Interfaces,
Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
which has a higher version number than imported assembly
`System.Reactive.Interfaces, Version=0.0.0.0, Culture=neutral,
PublicKeyToken=31bf3856ad364e35'
: error CS1705: Assembly `Akavache, Version=3.0.2.0, Culture=neutral,
PublicKeyToken=null' references `System.Reactive.Core, Version=2.1.30214.0,
Culture=neutral, PublicKeyToken=31bf3856ad364e35' which has a higher
version number than imported assembly `System.Reactive.Core,
Version=0.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'

This is because, in Akavache.Portable, if you crack open the binary using
monodis, you see that, despite the csproj referencing the MonoAndroid
version of System.Reactive.Core (having a version number of "0.0.0.0"),
you'll see that instead, the binary references the GAC'd mono version
("2.1.30214.0"). This breaks the build.

Any ideas?
=================================================================================================
Version info:
=== Xamarin Studio ===
 
Version 4.1.11 (build 10)
Installation UUID: 8aef1489-0e36-4a2e-94eb-00db2c5fc047
Runtime:
  Mono 3.2.3 ((no/8d3b4b7)
	GTK+ 2.24.20 theme: Raleigh
	GTK# (2.12.0.0)
	Package version: 302030000
 
=== Apple Developer Tools ===
 
Xcode 5.0 (3332.22)
Build 5A1412
 
=== Xamarin.iOS ===
 
Version: 7.0.0.11 (Business Edition)
Hash: aa35ba3
Branch: 
Build date: 2013-18-09 16:42:48-0400
 
=== Xamarin.Android ===
 
Version: 4.8.2 (Enterprise Edition)
Android SDK: /Users/paul/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.1   (API level 16)
		4.2   (API level 17)
		4.3   (API level 18)
Java SDK: /usr
java version "1.7.0_21"
Java(TM) SE Runtime Environment (build 1.7.0_21-b12)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)
 
=== Xamarin.Mac ===
 
Xamarin.Mac: 1.6.13
 
=== Build Information ===
 
Release ID: 401110010
Git revision: 6df7ab667918ee55a75f1adc93d53e3c9db392ae
Build date: 2013-09-14 00:09:49+0000
Xamarin addins: 7b3a1cd0b47c2a7b4530aaa2cc5e0077ee1001db
 
=== Operating System ===
 
Mac OS X 10.9.0
Darwin nyx.local 13.0.0 Darwin Kernel Version 13.0.0
    Fri Sep 13 23:35:55 PDT 2013
    root:xnu-2422.1.72~1/RELEASE_X86_64 x86_64
====================================================================================================
Test project:
https://github.com/github/akavache
Comment 2 Jon Goldberger [MSFT] 2013-09-24 19:26:53 UTC
Created attachment 4984 [details]
Log files
Comment 3 Jonathan Pryor 2013-09-24 20:49:15 UTC
@Goldberger:

Your `git clone` command is wrong, as it errors when I attempted to use it. This one works:

    git clone https://github.com/github/Akavache.git

Furthermore, the git repo contains 3 .sln files. Which one did you use?

Finally, it appears to be due to build artifacts. If I have a clean build environment, e.g. `git clean -d -x -f`, I can right-click > Build the *_Monodroid projects within Xamarin Studio and get _no_ errors, e.g. right-click Akavanche_Monodroid > Build Akavanche_monodroid.

The following binaries are generated:

> $ find Akavache/bin/Release/Monoandroid
> Akavache/bin/Release/Monoandroid
> Akavache/bin/Release/Monoandroid/Akavache.dll
> Akavache/bin/Release/Monoandroid/Akavache.dll.mdb
> Akavache/bin/Release/Monoandroid/Akavache.Portable.dll
> Akavache/bin/Release/Monoandroid/Akavache.Portable.dll.mdb
> Akavache/bin/Release/Monoandroid/Newtonsoft.Json.dll
> Akavache/bin/Release/Monoandroid/ReactiveUI.dll
> Akavache/bin/Release/Monoandroid/Splat.dll
> Akavache/bin/Release/Monoandroid/System.Reactive.Core.dll
> Akavache/bin/Release/Monoandroid/System.Reactive.Interfaces.dll
> Akavache/bin/Release/Monoandroid/System.Reactive.Linq.dll
> Akavache/bin/Release/Monoandroid/System.Reactive.PlatformServices.dll
Comment 4 Jonathan Pryor 2013-09-24 20:56:42 UTC
...BUT, just to make things "interesting", if I right-click Akavache_Monodroid > Set As Startup Project, then Build with Command+B, _then_ I get the errors...due to missing MonoMac.

Ah, Command+B builds everything in the configuration, regardless of the Startup Project, while Command+K builds the active project, and Command+K builds w/o error IFF *_Monodroid projects are built _first_. My bad.
Comment 6 Jonathan Pryor 2013-09-24 21:14:27 UTC
TL;DR: Don't share `obj` directories between different projects.

From a Clean environment, if I "just Build" from the Akavache_XSAll.sln
project, I get the following diagnostic build output:

https://gist.github.com/jonpryor/9fc94e6acf9ed7495128

The problem appears to be in
Akavache.Portable/Akavache.Portable_MonoMac.csproj:

> Project "/Users/jon/tmp/Akavache/Akavache.Portable/Akavache.Portable_MonoMac.csproj" (Build target(s)):
...
> 		Primary Reference System.Reactive.Interfaces, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35
> 			Reference System.Reactive.Interfaces, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 resolved to /Library/Frameworks/Mono.framework/Versions/3.2.0/lib/mono/4.5/System.Reactive.Interfaces.dll. CopyLocal = False
> 			Reference found at search path {TargetFrameworkDirectory}

So Akavache.Portable_MonoMac.csproj is importing the "versioned"
System.Reactive.Interfaces, which is pulled from the GAC. So let's look at
Akavache.Portable/Akavache.Portable_MonoMac.csproj:

>     <Reference Include="System.Reactive.Interfaces, Version=2.1.30214.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
>       <Private>False</Private>
>     </Reference>

Compare to Akavache.Portable/Akavache.Portable_Monodroid.csproj:

>     <Reference Include="System.Reactive.Interfaces">
>       <HintPath>..\ext\monodroid\System.Reactive.Interfaces.dll</HintPath>
>     </Reference>

Oh. Well, that's probably it...

Furthermore, I can't "fix" the *_MonoMac.csproj files to use a
*_Monodroid-style unversioned reference, as there isn't a MonoMac-specific
..\ext\monomac\System.Reactive.Interfaces.dll assembly.

Which leads to the next problem: The reason why the *_Monodroid.csproj projects
are grabbing the *_MonoMac.csproj binaries is because they all use the same
`obj\Release` directory, so whichever is built first "wins".  This _can_ be
fixed by setting the $(IntermediateOutputPath) MSBuild property:

https://gist.github.com/jonpryor/36f9550736c01fbfc19b

The result is that the CS1705 errors have been removed.