Bug 17028 - Possible regression: HttpClient in .NET 4.5 PCL causes error "Could not load type 'System.Runtime.Versioning.BinaryCompatibility'"
Summary: Possible regression: HttpClient in .NET 4.5 PCL causes error "Could not load ...
Status: RESOLVED NOT_REPRODUCIBLE
Alias: None
Product: Visual Studio Extensions
Classification: Xamarin
Component: iOS ()
Version: 1.10.x
Hardware: PC Mac OS
: Normal normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-01-02 19:42 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2015-08-04 13:53 UTC (History)
9 users (show)

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


Attachments
Test case (40.29 KB, application/zip)
2014-01-02 19:42 UTC, Brendan Zagaeski (Xamarin Team, assistant)
Details
App.config for workaround (431 bytes, application/octet-stream)
2014-01-07 13:10 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 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 NOT_REPRODUCIBLE

Description Brendan Zagaeski (Xamarin Team, assistant) 2014-01-02 19:42:42 UTC
Created attachment 5750 [details]
Test case

It looks like this might be a variation or duplicate of bug #16766. Similar to that case, with Xamarin.iOS 1.10 the iPhoneSimulator app bundle contains symlinks into ~/Library/Caches/Xamarin for some of the System DLLs. One difference is that this time the problematic reference is a real PCL.

## Runtime exception on iPhone Simulator after clicking "Click me"

System.Configuration.ConfigurationErrorsException: Configuration system failed to initialize ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.Uri ---> System.TypeInitializationException: An exception was thrown by the type initializer for System.UriParser ---> System.TypeLoadException: Could not load type 'System.Runtime.Versioning.BinaryCompatibility' from assembly 'System'


## Build error on iPhone with "Link SDK assemblies only" or "Link all assemblies"

> error MT2001: Could not link assemblies. Reason: Argument cannot be null.
> Parameter name: key


## Build errors on iPhone with "Don't link"
> error MT3001: Could not AOT the assembly '/Users/username/Library/Caches/Xamarin/mtbs/builds/HelloWorld2/b819e1bb-d718-404e-ad33-6739787a7253/output/temp/mtouch-cache/Build/System.Core.dll'
> error MT3001: Could not AOT the assembly '/Users/username/Library/Caches/Xamarin/mtbs/builds/HelloWorld2/b819e1bb-d718-404e-ad33-6739787a7253/output/temp/mtouch-cache/Build/System.dll'
> error MT3001: Could not AOT the assembly '/Users/username/Library/Caches/Xamarin/mtbs/builds/HelloWorld2/b819e1bb-d718-404e-ad33-6739787a7253/output/temp/mtouch-cache/Build/System.Configuration.dll'
> error MT3001: Could not AOT the assembly '/Users/username/Library/Caches/Xamarin/mtbs/builds/HelloWorld2/b819e1bb-d718-404e-ad33-6739787a7253/output/temp/mtouch-cache/Build/System.Xml.dll'


## Steps to reproduce

1. Open the attached solution (in VS 2013).

2. Attempt to deploy the HelloWorld1 project to iPhoneSimulator or iPhone.

3. If running on the iPhoneSimulator, click the "Click me" button.


## Version information, regression status

_Fails_ on Windows with:
Xamarin.iOS 1.10.30

_Works_ for all cases on Windows with:
Xamarin.iOS 1.8.365

_Works_ for all cases on Mac in Xamarin Studio.

### Build host version information
Xamarin.iOS 7.0.6.166
Mono 3.2.6
Xamarin Studio 4.2.2
Comment 1 Brendan Zagaeski (Xamarin Team, assistant) 2014-01-07 13:08:31 UTC
Additional information from another user:

This looks like a bug in the PCL unification code.

The issue was that a reference to System.Net.Http v4.0 was not properly unified to 2.0.5.0 as is in the façade directory.


## Workaround

1. Add the attached App.config file to the HelloWorld1 project
2. Clean the solution.
3. Confirm that the `bin/` and `obj/` folders are empty on the Windows side
4. Confirm that the corresponding folder in `~/Library/Caches/Xamarin/mtbs` is empty on the Mac side
5. Build and deploy the project.


The App.config file contains the following redirect:

> <dependentAssembly>
>   <assemblyIdentity name="System.Net.Http" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
>   <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="2.0.5.0" />
> </dependentAssembly>


## Detailed build log shows that System.Net.Http is resolved to the GAC version

>Dependency "System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
>    Resolved file path is "C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll".

And a little farther down...

>        Considered "C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\MonoTouch\v1.0\System.Net.Http.dll", but its name "System.Net.Http, Version=2.0.5.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" didn't match.
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2014-01-07 13:10:05 UTC
Created attachment 5775 [details]
App.config for workaround
Comment 3 Brendan Zagaeski (Xamarin Team, assistant) 2014-01-07 13:13:35 UTC
## Results with latest build of XamarinVS
Building the test case with the latest XamarinVS produces some nice new warning messages (from the fix for bug 16766). Using the App.config workaround successfully removes these warnings.

> WARNING: application references a .NET FX assembly C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Net.Http\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Net.Http.dll. It will most likely cause the Mac side build to fail.
> WARNING: application references a .NET FX assembly C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll. It will most likely cause the Mac side build to fail.
> WARNING: application references a .NET FX assembly C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll. It will most likely cause the Mac side build to fail.
> WARNING: application references a .NET FX assembly C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll. It will most likely cause the Mac side build to fail.
> WARNING: application references a .NET FX assembly C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll. It will most likely cause the Mac side build to fail.
> WARNING: application references a .NET FX assembly C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Security\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Security.dll. It will most likely cause the Mac side build to fail.
> WARNING: application references a .NET FX assembly C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Numerics\v4.0_4.0.0.0__b77a5c561934e089\System.Numerics.dll. It will most likely cause the Mac side build to fail.
> WARNING: application references a .NET FX assembly C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.SqlXml\v4.0_4.0.0.0__b77a5c561934e089\System.Data.SqlXml.dll. It will most likely cause the Mac side build to fail.
Comment 9 Udham Singh 2015-08-04 12:21:00 UTC
I have checked this issue with the help of test steps given in bug description with latest stable builds and I am able to run the app successfully.

Screencast : http://www.screencast.com/t/iTZ2cGVS

For now I am closing this issue. If you are still getting this issue, please feel free to reopen this issue.

Environment Info : 

Microsoft Visual Studio Professional 2013
Version 12.0.31101.00 Update 4
Microsoft .NET Framework
Version 4.5.50938

Installed Version: Professional

Xamarin   3.11.666.0 (ebae43a)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin.Android   5.1.4.16 (5f55a9ef61c11b6ce0890bc91e4c71b1b92be214)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.iOS   8.10.2.0 (67b390d0d1bd741582cf7b7fd3ffea08583a3f83)
Visual Studio extension to enable development for Xamarin.iOS.