xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.45k stars 511 forks source link

Linker behaviour inconsistent #5652

Closed shivinder5 closed 5 years ago

shivinder5 commented 5 years ago

Steps to Reproduce

Run in simulator with the three linker options. Don't link, Link All and Framework SDKs. Only works when i have it as Don't link.

Expected Behavior

I would think it would not give me a bug with either of the options.

Actual Behavior

When i run with Don't link it works. When i run with Link Framework SDK's only i get the following error. Severity Code Description Project File Line Suppression State Error Failed to resolve "System.Configuration.ConfigurationException" reference from "System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" PariluxPhoneApp.iOS
I know it is coming from my awssdkcore.dll(there is a warning that says Severity Code Description Project File Line Suppression State Warning Cannot find the assembly 'System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' referenced from '/Users/ShivS/Library/Caches/Xamarin/mtbs/builds/PariluxPhoneApp.iOS/98c804eb838feaea8c4918f655cc8e49/bin/iPhoneSimulator/Debug/AWSSDK.Core.dll'. PariluxPhoneApp.iOS

When i run in Link all it runs but it gives me a run time exception about Default constructor not found for a dependency for ios specific impplimentation. This is not a problem when i run with don't link

Environment

Version 15.9.4 VisualStudio.15.Release/15.9.4+28307.222 Microsoft .NET Framework Version 4.7.03056

Installed Version: Community

Visual C++ 2017 00369-60000-00001-AA869 Microsoft Visual C++ 2017

ADL Tools Service Provider 1.0 This package contains services used by Data Lake tools

Application Insights Tools for Visual Studio Package 8.14.11009.1 Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2017 15.9.04012.0 ASP.NET and Web Tools 2017

ASP.NET Core Razor Language Services 15.8.31590 Provides languages services for ASP.NET Core Razor.

ASP.NET Web Frameworks and Tools 2012 4.0.30625.0 For additional information, visit https://www.asp.net/

ASP.NET Web Frameworks and Tools 2017 5.2.60913.0 For additional information, visit https://www.asp.net/

AWS Toolkit for Visual Studio 2017 1.14.4.1 AWS Toolkit for Visual Studio 2017. Copyright 2011-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.

Release notes: https://aws-vs-toolkit.s3.amazonaws.com/versioninfo.html

This software includes third party software subject to the following copyrights:

Azure App Service Tools v3.0.0 15.9.03024.0 Azure App Service Tools v3.0.0

Azure Data Lake Node 1.0 This package contains the Data Lake integration nodes for Server Explorer.

Azure Data Lake Tools for Visual Studio 2.3.5001.4 Microsoft Azure Data Lake Tools for Visual Studio

Azure Stream Analytics Tools for Visual Studio 2.3.5001.4 Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools 2.10.0-beta2-63501-03+b9fb1610c87cccc8ceb74a770dba261a58e39c4a C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

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

Cookiecutter 15.9.18254.1 Provides tools for finding, instantiating and customizing templates in cookiecutter format.

Extensibility Message Bus 1.1.49 (remotes/origin/d15-8@ee674f3) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

JavaScript Language Service 2.0 JavaScript Language Service

JavaScript Project System 2.0 JavaScript Project System

JavaScript UWP Project System 2.0 JavaScript UWP Project System

Microsoft Azure HDInsight Azure Node 2.3.5001.4 HDInsight Node under Azure Node

Microsoft Azure Hive Query Language Service 2.3.5001.4 Language service for Hive query

Microsoft Azure Stream Analytics Language Service 2.3.5001.4 Language service for Azure Stream Analytics

Microsoft Azure Stream Analytics Node 1.0 Azure Stream Analytics Node under Azure Node

Microsoft Azure Tools 2.9 Microsoft Azure Tools for Microsoft Visual Studio 2017 - v2.9.10730.2

Microsoft Continuous Delivery Tools for Visual Studio 0.4 Simplifying the configuration of Azure DevOps pipelines from within the Visual Studio IDE.

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Microsoft Library Manager 1.0 Install client-side libraries easily to any web project

Microsoft MI-Based Debugger 1.0 Provides support for connecting Visual Studio to MI compatible debuggers

Microsoft Visual C++ Wizards 1.0 Microsoft Visual C++ Wizards

Microsoft Visual Studio Tools for Containers 1.1 Develop, run, validate your ASP.NET Core applications in the target environment. F5 your application directly into a container with debugging, or CTRL + F5 to edit & refresh your app without having to rebuild the container.

Microsoft Visual Studio VC Package 1.0 Microsoft Visual Studio VC Package

MLGen Package Extension 1.0 MLGen Package Visual Studio Extension Detailed Info

Mono Debugging for Visual Studio 4.13.12-pre (9bc9548) Support for debugging Mono processes with Visual Studio.

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

Office Developer Tools for Visual Studio 2017 ENU 15.0.28224.00 Microsoft Office Developer Tools for Visual Studio 2017 ENU

ProjectServicesPackage Extension 1.0 ProjectServicesPackage Visual Studio Extension Detailed Info

Python 15.9.18254.1 Provides IntelliSense, projects, templates, debugging, interactive windows, and other support for Python developers.

Python - Django support 15.9.18254.1 Provides templates and integration for the Django web framework.

Python - IronPython support 15.9.18254.1 Provides templates and integration for IronPython-based projects.

Python - Profiling support 15.9.18254.1 Profiling support for Python projects.

ResourcePackage Extension 1.0 ResourcePackage Visual Studio Extension Detailed Info

ResourcePackage Extension 1.0 ResourcePackage Visual Studio Extension Detailed Info

SourceGear Vault Standard Visual Studio Extension 10.0.2.939 The SourceGear Vault Standard Source Code Control Extension enables source code control integration from within Visual Studio. For more information about Vault Standard, visit http://www.sourcegear.com.

SQL Server Data Tools 15.1.61810.11040 Microsoft SQL Server Data Tools

ToolWindow Extension 1.0 ToolWindow Visual Stuido Extension Detailed Info

ToolWindowHostedEditor 1.0 Hosting json editor into a tool window

TypeScript Tools 15.9.20918.2001 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 2.10.0-beta2-63501-03+b9fb1610c87cccc8ceb74a770dba261a58e39c4a Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 10.2 for F# 4.5 15.8.0.0. Commit Hash: 6e26c5bacc8c4201e962f5bdde0a177f82f88691. Microsoft Visual F# Tools 10.2 for F# 4.5

Visual Studio Code Debug Adapter Host Package 1.0 Interop layer for hosting Visual Studio Code debug adapters in Visual Studio

Visual Studio Tools for Containers 1.0 Visual Studio Tools for Containers

Visual Studio Tools for Universal Windows Apps 15.0.28307.208 The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.

VisualStudio.Mac 1.0 Mac Extension for Visual Studio

Workflow Manager Tools 1.0 1.0 This package contains the necessary Visual Studio integration components for Workflow Manager.

Xamarin 4.12.3.77 (d15-9@e3f40b477) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 4.16.13 (45a16efd4) Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates 1.1.128 (6f5ebb2) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK 9.1.4.2 (HEAD/8255f42fc) Xamarin.Android Reference Assemblies and MSBuild support.

Xamarin.iOS and Xamarin.Mac SDK 12.2.1.12 (65ec520) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Build Logs

Below are the logs. I have the logs with all 3 linker options. I know there are some nuget packages that have been updated for .net standard but they work well in the simulator Logs.txt

Example Project (If Possible)

sorry big project.

mandel-macaque commented 5 years ago

Hello, the issue seems to be that the linker is removing certain parts of the code that are not used to minimise the size of the application. There are several ways to work around it:

  1. If it is your code, use the correct attributes to ensure that the code is not removed by the linker. (PreserveAttribute)
  2. Marking your Assembly as Linker-ready.
  3. Create a custom linker configuration to ensure that the needed code is not removed.

You can find more documentation about 1 and 2 here. Documentation about how to create the linker config can be found here.

Perse it is not a bug. What happens is the linker is not seeing the code used, and it is removing it. The errors are different, between Link All and Link Framework SDK's due to how aggressive is the linker.

I'm closing the issue, but please, if you do not find the answer good enough, reopen it and we will have a closer look.

mandel-macaque commented 5 years ago

Sorry, they have brought to my attention that you are not dealing with a mobile app, reopening to double check.

shivinder5 commented 5 years ago

Hey mandel. it is a mobile app but I am using a library I use in a non mobile app. I actually was able to partially solve it. I realized that one of the libraries I reference was supposed to pull in some system files it did not. I am still having the problem with the link all option where it insists that it does not find a constructor for a dependency. But if I run using the second option it works. which is good enough for me. Thank you for your help.

mandel-macaque commented 5 years ago

Ok! Thanks for the clarification. In that case, ou might find issues with the AOT compiler even with don't link. Closing the issue since it is prese not a bug in the platform.