Bug 27469 - [Android][Windows] System.Runtime is missing error at compile time when trying to add a reference on binding to PCL
Summary: [Android][Windows] System.Runtime is missing error at compile time when tryin...
Status: CLOSED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: General ()
Version: 4.20.0
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: dean.ellis
URL:
Depends on:
Blocks:
 
Reported: 2015-02-26 14:06 UTC by Dominic N [MSFT]
Modified: 2017-04-20 02:40 UTC (History)
9 users (show)

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


Attachments
Test case (12.78 KB, application/zip)
2015-03-07 00:16 UTC, Brendan Zagaeski (Xamarin Team, assistant)
Details
Diagnostic build output (442.71 KB, text/plain)
2015-03-07 00:17 UTC, Brendan Zagaeski (Xamarin Team, assistant)
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:
CLOSED FIXED

Description Dominic N [MSFT] 2015-02-26 14:06:42 UTC
## Overview

There seems to be in issue with Android bindings in Windows. A customer is experiencing an issue when trying to add an extra class on a binding project where said class must use some types on a PCL.

When there's a reference on the Binding to the PCL and it is compiled, System.Runtime is missing errors show up.


## Steps to reproduce

1. Create an empty binding project on Windows and bind to any jar/aar
2. Add a reference to NuGet package PI.SDK on the binding project
    - This was written by the customer and is targeting: .NET 4.5, Windows 8, WP8.1, WP Silverlight 8, XA, XI, XI (Classic)
3. Create a class in the binding library on the folder Additionals with any name and make it implement interface 'IBluetoothDeviceManager' from the PI.SDK PCL.
4. Build


## Expected results

Project should build successfully (as it does on a Mac).


## Actual results

Project throws System.Runtime is missing errors on Windows machines (XS and VS).


## Version information

=== Xamarin Studio ===

Version 5.7.1 (build 17)
Installation UUID: d4e351b9-4846-465f-9dd4-9f35d5781c8c
Runtime:
	Microsoft .NET 4.0.30319.0
	GTK+ 2.24.22 (MS-Windows theme)
	GTK# 2.12.25

=== Xamarin.Android ===

Version: 4.20.0 (Business Edition)
Android SDK: C:\Users\Gutemberg\AppData\Local\Android\android-sdk
	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.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)
Java SDK: C:\Program Files (x86)\Java\jdk1.7.0_71
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) Client VM (build 24.71-b01, mixed mode, sharing)

=== Build Information ===

Release ID: 507010017
Git revision: 0bc7d3550b6b088ac25b08dcf7bbe73bcc8658b3
Build date: 2015-02-03 19:51:07-05
Xamarin addins: f7b7d34419c9ec24501bfa7c658e80a6305613e0

=== Operating System ===

Windows 6.2.9200.0 (64-bit)


==============================================
Microsoft Visual Studio Ultimate 2013
Version 12.0.31101.00 Update 4
Microsoft .NET Framework
Version 4.6.00007

Installed Version: Ultimate

Architecture and Modeling Tools   06181-004-0449004-02884
Microsoft Architecture and Modeling Tools
    
UML® and Unified Modeling Language™ are trademarks or registered trademarks of the Object Management Group, Inc. in the United States and other countries.

Team Explorer for Visual Studio 2013   06181-004-0449004-02884
Microsoft Team Explorer for Visual Studio 2013

Visual Basic 2013   06181-004-0449004-02884
Microsoft Visual Basic 2013

Visual C# 2013   06181-004-0449004-02884
Microsoft Visual C# 2013

Visual C++ 2013   06181-004-0449004-02884
Microsoft Visual C++ 2013

Visual F# 2013   06181-004-0449004-02884
Microsoft Visual F# 2013

Visual Studio 2013 Code Analysis Spell Checker   06181-004-0449004-02884
Microsoft® Visual Studio® 2013 Code Analysis Spell Checker

Portions of International CorrectSpell™ spelling correction system © 1993 by Lernout & Hauspie Speech Products N.V. All rights reserved.

The American Heritage® Dictionary of the English Language, Third Edition Copyright © 1992 Houghton Mifflin Company. Electronic version licensed from Lernout & Hauspie Speech Products N.V. All rights reserved.

Windows Phone SDK 8.0 - ENU   06181-004-0449004-02884
Windows Phone SDK 8.0 - ENU

Application Insights Tools for Visual Studio Package   1.0
Application Insights Tools for Visual Studio

Common Azure Tools   1.3
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Microsoft Azure Mobile Services Tools   1.3
Microsoft Azure Mobile Services Tools

Microsoft BizTalk Server 2013 R2   07354-270-2367593-04103
Microsoft BizTalk Server 2013 R2

Microsoft.ServiceModel.Channels.MapperItem   1.0
Package to add the mapper activity to the WF toolbox

MonoDebugger.VS2013   1.0
Information about my package

NuGet Package Manager   2.8.50926.663
NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.

PowerShell Tools   1.3
Provides file classification services using PowerShell

PreEmptive Analytics Visualizer   1.2
Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.

Xamarin   3.9.302.0 (80f4e84)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   4.20.0.34 (49a04b966feb40dfdba49d57ba16249b66d606a6)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   8.6.1.0 (3b3ef438017c7ecf486defa9e01567a5f2b3cb2a)
Visual Studio extension to enable development for Xamarin.iOS.

Xamarin.iOS Unified Migration   1.0
Automated migration for Xamarin iOS Classic projects to Unified
Comment 2 Gutemberg 2015-02-26 14:31:56 UTC
In order to keep the same environment, when Installing the nuget package, please add this specific version: https://www.nuget.org/packages/PI.SDK/0.1.5043.1 and not the latest that has several changes.

Also, I've noticed similar behavior on Android projects that isn't binding but android class libraries or even Application. It ask to add not just System.Runtime, but System.Collections, System.Collections.Generics, System.Threading.Tasks and so on. All facade assemblies...

Also, the binding project when referenced on the Android app or class library project, doesn't appear on the Assembly browser with the namespaces. (VS and XS)

The binding on Android is becoming buggy with the past of the updates on Xamarin. I don't know why... Maybe if we have some AOT compilation(now Java supports it on latest Android releases) as we do on iOS, many of those problems and buggy inconsistences would be reduced.

We still stuck here since the binding project just don't work.

All we need to do is make:

1. Create inside the binding project a extra class and implement on it a Interface that comes from a referenced PCL dll.
2. Make the classes generated by the binding to implement one interface that comes from the referenced PCL dll.

Thanks
Comment 3 Atsushi Eno 2015-02-26 14:48:06 UTC
Android binding project is Android specific and therefore incompatible with PCL by nature.
Comment 4 Gutemberg 2015-02-26 14:50:12 UTC
OK about android binding, but what about the class library and application that has the same issue?
Comment 5 Jonathan Pryor 2015-02-27 10:54:57 UTC
> Project should build successfully (as it does on a Mac).

I'll readily admit this is a bug: if it builds on Mac, it should build on Windows (...within reason...).

Could you please attach a complete project which exhibits this issue?

Thanks,
 - Jon
Comment 6 Gutemberg 2015-02-27 11:03:04 UTC
Hello Jon, 

There is no unique project that this happen Jon. If you follow the steps and create one yourself, add the nuget as explained here, you should see the same problem.

1. Create a java binding and bind to anything (specially .aar files)
2. Add this https://www.nuget.org/packages/PI.SDK/0.1.5043.1 to the project
3. Create a class inside binding project that implements IBluetoothDeviceManager

Build and you will see what happens. The same happens if you add it to other project as well.

Thanks
Comment 7 Brendan Zagaeski (Xamarin Team, assistant) 2015-03-07 00:16:46 UTC
Created attachment 10195 [details]
Test case

## Workaround

In case it's helpful, I _think_ a valid temporary workaround is to manually add a reference to the bindings project for each of the following facade assemblies:

> C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\Facades\System.Runtime.dll
> C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\Facades\System.Threading.Tasks.dll
> C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoAndroid\v1.0\Facades\System.Collections.dll

This stops the problem in the attached test case, and I believe it's the desired behavior.


## Steps to reproduce

1. Unzip attached test case.

2. Restore the NuGet packages.

3. msbuild /t:Build AndroidBindingsLibrary1.sln



## Results

### Excerpts from the diagnostic build output

The problematic references are apparently resolved to the GAC versions rather than the Xamarin.Android facades.

>   Dependency "System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". (TaskId:15)
>       Resolved file path is "C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Runtime\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Runtime.dll". (TaskId:15)
 
>  Dependency "System.Threading.Tasks, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". (TaskId:15)
>      Resolved file path is "C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Threading.Tasks\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Threading.Tasks.dll". (TaskId:15)

>  Dependency "System.Collections, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a". (TaskId:15)
>      Resolved file path is "C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Collections\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Collections.dll". (TaskId:15)


Corresponding build errors:

> Class1.cs(9,11): error CS0012: The type 'System.Exception' is defined in an
> assembly that is not referenced. You must add a reference to assembly
> 'System.Runtime, Version=4.0.0.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a'.

> Class1.cs(9,11): error CS0012: The type 'System.Threading.Tasks.Task`1<T0>'
> is defined in an assembly that is not referenced. You must add a reference
> to assembly 'System.Threading.Tasks, Version=4.0.0.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a'.

> Class1.cs(9,11): error CS0012: The type
> 'System.Collections.Generic.Dictionary`2<T0,T1>' is defined in an assembly
> that is not referenced. You must add a reference to assembly
> 'System.Collections, Version=4.0.0.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a'.



### Succeeds with `xbuild` on Mac

`xbuild /t:Build AndroidBindingsLibrary1.sln` completes successfully.



## Version info

### Windows 8.1 64-bit, in VMWare Fusion 6.0.5 (2209127)
Microsoft Visual Studio Professional 2013
Version 12.0.30723.00 Update 3
Microsoft .NET Framework
Version 4.5.51641

Xamarin   3.9.344.0 (e23ab72)
Xamarin.Android   4.20.0.34 (49a04b966feb40dfdba49d57ba16249b66d606a6)
Xamarin.iOS   8.6.2.0 (862702c6b8aa14a373e25f83ac45918556af41a2)

Windows 6.2.9200.0 (64-bit)
Comment 8 Brendan Zagaeski (Xamarin Team, assistant) 2015-03-07 00:17:42 UTC
Created attachment 10196 [details]
Diagnostic build output
Comment 9 Brendan Zagaeski (Xamarin Team, assistant) 2015-03-07 00:33:27 UTC
This looks quite closely related to bug 26149.
Comment 10 Paul Read 2015-09-08 06:41:14 UTC
I have this same issue.  Project builds on MAC but not on Windows giving errors like:

C:\dev_xam\MyTAS\app\Droid\MainActivity.cs(18,18): Error CS0012: The type 'System.Threading.Tasks.Task' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Threading.Tasks, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. (CS0012) (MyTAS.Droid)
Comment 11 Suat Korkmaz 2017-04-18 13:15:26 UTC
In my case, VS can build the binding project and I can see the .dll in the Debug folder however, I can NOT see the classes of the .dll in the Object Browser. The .dll looks empty but it is not. The app runs OK as it should but there is no way I can use assemblies and classes while I'm developing.
Comment 12 Brendan Zagaeski (Xamarin Team, assistant) 2017-04-20 02:39:15 UTC
> VS can build the binding project and I can see the .dll in the Debug
> folder

This bug report is specifically about a build error that prevented a binding library from building at all.  Issues after VS builds the binding project successfully would be outside the scope of this particular bug report.
Comment 13 Brendan Zagaeski (Xamarin Team, assistant) 2017-04-20 02:39:39 UTC
For a bit of Wednesday evening fun, I'll also do a quick verification pass on this old bug report.




## Verification status: verified fixed in XamarinVS 4.2.2, Xamarin.Android 7.0.2 (if not earlier)

> GOOD: XamarinVS 4.4.0.34    (3f99c5a), Xamarin.Android 7.2.0.7  (b16fb82)
> GOOD: XamarinVS 4.2.2.11    (00fa5cc), Xamarin.Android 7.0.2.42 (501e63c)
> BAD:  XamarinVS 3.11.1594.0 (a06d6d5), Xamarin.Android 5.1.7.12 (53fce3730830417896a42f365a5ba35f1ee58d9d)



## Verification steps

1. I re-tested the steps from Comment 7 on the old version to ensure I was able to hit the original errors.

2. I then tested on the newer version and verified that the build errors no longer occur.




## Additional testing environment info

Microsoft Visual Studio Enterprise 2015
Version 14.0.25431.01 Update 3
Microsoft .NET Framework
Version 4.6.01586

Windows 10 (64-bit) Version 1607 (OS Build 14393.1066)
US English locale, US Eastern time zone