Bug 31379 - [XI 8.10] Enabling linker for PCL with "duplicate" System.Net.Primitives references causes "Could not load file or assembly 'System.Net.Primitives'" on simulator
Summary: [XI 8.10] Enabling linker for PCL with "duplicate" System.Net.Primitives refe...
Status: VERIFIED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: XI 8.10
Hardware: PC Mac OS
: Low minor
Target Milestone: 9.2 (C6)
Assignee: Bugzilla
URL:
: 31258 ()
Depends on:
Blocks: 31560
  Show dependency tree
 
Reported: 2015-06-25 13:45 UTC by Brendan Zagaeski (Xamarin Team, assistant)
Modified: 2015-11-16 13:49 UTC (History)
6 users (show)

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


Attachments
Test case (29.32 KB, application/zip)
2015-06-25 13:45 UTC, Brendan Zagaeski (Xamarin Team, assistant)
Details
Logs and version information (116.56 KB, application/zip)
2015-06-25 13:48 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:
VERIFIED FIXED

Description Brendan Zagaeski (Xamarin Team, assistant) 2015-06-25 13:45:36 UTC
Created attachment 11737 [details]
Test case

This is a new bug to provide a minimal from-scratch test case for Bug 31258.


The behavior seems to be closely related to Bug 29211, but Bug 29211 is resolved in XI 8.10.2.37 while this bug is _not_.




## Workaround

As with Bug 29211, it is possible to stop the error by adding "-linkskip=System.Net.Primitives" under "project options -> iOS Build -> Additional mtouch arguments".




## Regression status: regression between XI 8.9 and XI 8.10

BAD:  Xamarin.iOS 8.10.2.37  (ef8c2f7)
BAD:  Xamarin.iOS 8.10.2.35  (248c95e)
BAD:  Xamarin.iOS 8.10.0.267 (6481535)
GOOD: Xamarin.iOS 8.9.1.3    (f7736a4)




## Steps to reproduce

Build and run the attached test case in the "Debug|iPhoneSimulator" configuration.




## Results

The app crashes due to a missing "System.Net.Primitives" dependency.



### Excerpt from the simulator console log

> System.IO.FileNotFoundException: Could not load file or assembly 'System.Net.Primitives' or one of its dependencies. The system cannot find the file specified.
> File name: 'System.Net.Primitives'
>   at System.AppDomain.Load (System.Reflection.AssemblyName assemblyRef, System.Security.Policy.Evidence assemblySecurity) [0x00081] in /Users/builder/data/lanes/1880/248c95e2/source/mono/mcs/class/corlib/System/AppDomain.cs:706 



### Related build warning from the diagnostic build output

> There was a conflict between "System.Net.Primitives, Version=4.0.0.0,
> Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" and "System.Net.Primitives,
> Version=3.9.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".



### Assemblies referenced by the Windows-compiled `PortableClassLibrary1.dll`

> monop -r:UnifiedSingleViewIphone1/libs/PortableClassLibrary1.dll --refs
> System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
> System.Resources.ResourceManager, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
> Refit, Version=2.2.1.0, Culture=neutral, PublicKeyToken=null
> System.Net.Primitives, Version=3.9.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
> System.Net.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

Note the duplicate reference to "System.Net.Primitives".




## Expected results



- The app does _not_ hit this error when deployed and run on an iOS _device_ rather than an iOS simulator. This is probably related to the change in XI 8.10 that attempts to load all assemblies at startup when running on simulator (see also non-public Bug 29211, Comment 5).



- The app does _not_ hit the error if you rebuild "PortableClassLibrary1.dll" using `xbuild` and `mcs` on Mac. When built using `xbuild` and `mcs`, "PortableClassLibrary1.dll" does not contain a duplicate "System.Net.Primitives" reference:

> monop -r:PortableClassLibrary1/bin/Debug/PortableClassLibrary1.dll --refs
> Refit, Version=2.2.1.0, Culture=neutral, PublicKeyToken=null
> System.Net.Primitives, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
> System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
> System.Resources.ResourceManager, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a




## Brief description of the test case

1. Create a new single view iPhone app project and a new PCL project.

2. Add a reference to the "Refit" NuGet package to both projects.

3. Add the following lines to the PCL project:

> catch (ApiException apiEx)
> {
>     switch (apiEx.StatusCode)
>     {
>         case HttpStatusCode.NotFound:
>             break;
>         case HttpStatusCode.InternalServerError:
>             break;
>     }
> }

4. Build the PCL project using MSBuild + `csc` on Windows.

5. Add the compiled `.dll` as a reference in the iPhone app project.
Comment 1 Brendan Zagaeski (Xamarin Team, assistant) 2015-06-25 13:48:10 UTC
Created attachment 11738 [details]
Logs and version information
Comment 2 Brendan Zagaeski (Xamarin Team, assistant) 2015-06-25 13:58:10 UTC
*** Bug 31258 has been marked as a duplicate of this bug. ***
Comment 4 Sebastien Pouliot 2015-06-30 12:42:44 UTC
update: SR3 -> 8.10.4

workaround: do not use the linker in simulator builds - it does not only solve the problem, builds are also _much_ faster this way
Comment 5 Ian Ceicys 2015-07-14 10:02:28 UTC
Just to close out this bug. I have verified I am able to run the attached
sample and deploy to the iPhoneSimulator without any issue. 

Version Info:
Microsoft Visual Studio Ultimate 2013
Version 12.0.31101.00 Update 4
Microsoft .NET Framework
Version 4.6.00079

Xamarin   3.11.774.0 (d6c2770)
Visual Studio extension to enable development for Xamarin.iOS and
Xamarin.Android.

Xamarin.Android   5.1.5.0 (f6f57295eea6943c084c101f953ef699a5dc82c8)
Visual Studio plugin to enable development for Xamarin.Android.

Xamarin.Forms Intellisense   1.0
Provides intellisense for Xamarin.Forms in the XML editor.

Xamarin.iOS   8.10.4.0 (c57a2c7d806a18cc56c1f9f3aaf91cb17b791d02)
Visual Studio extension to enable development for Xamarin.iOS
Comment 6 Brendan Zagaeski (Xamarin Team, assistant) 2015-07-14 13:37:15 UTC
I think comment 5 might have been intended for a different bug? The issue for this bug is an unhandled exception that occurs during the app startup process (after building and deploying).

That exception still happens on Xamarin.iOS 8.10.4.10 (c57a2c7) (optionally also using XamarinVS 3.11.774.0 (d6c2770) to deploy and debug from Windows).
Comment 10 Sebastien Pouliot 2015-09-03 14:45:13 UTC
Updating milestone (the C6 release will be 9.2).
Comment 11 Brendan Zagaeski (Xamarin Team, assistant) 2015-09-23 17:42:13 UTC
I am happy with calling this resolved on Xamarin.iOS 9.0 and Xamarin.iOS 9.2. In both versions the app now runs successfully on simulator. I will leave the target milestone unchanged for now. QA, if you like feel free to set the target milestone back to 9.0 after verifying on both versions.


The Application Output still shows a diagnostic error message:

> Could not find `System.Net.Primitives` referenced by assembly `PortableClassLibrary1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null`.


But I think that's fine because the app does run successfully on the simulator.
Comment 12 GouriKumari 2015-11-16 13:49:39 UTC
Verified bug with current alpha builds and the testapp did execute successfully on iOS simulator. However, as mentioned in comment#11, application output does show the same diagnostic error message.  Based on comment#11 and  on my verification, I am marking this as verified.

Logs:

Application Output: 
https://gist.github.com/GouriKumari/19f5a06e6d82f6261e94

Build Output: https://gist.github.com/GouriKumari/dd69b9105ab2562a872b

Test Env: https://gist.github.com/GouriKumari/264d2dbc7d4ed16b487c