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

Tooling is not removing a dll that is no longer referenced by code unless you rebuild #5588

Open PureWeen opened 5 years ago

PureWeen commented 5 years ago

Steps to Reproduce

Make sure to have linking turned off

  1. download the project
  2. deploy ios app to device (I was deploying to a simulator)
  3. comment out the following code in the AppDelegate
    public void SomeRandomReference()
        {
             throw new Exception(typeof(ExtraLibrary.Class1).Name);
        }
  4. deploy ios app to device and you will notice that in the AppDelegate.cs file it's able to call Assembly.Load("ExtraLibrary"); successfully
  5. rebuild ios app
  6. run ios app and now it will crash when trying to call Assembly.Load("ExtraLibrary");

Expected Behavior

Behavior before rebuild should be the same as after rebuild

Actual Behavior

A rebuild is required in order for the dll that's no longer referenced in code to not be included with the app

Environment

Microsoft Visual Studio Enterprise 2019 Int Preview
Version 16.0.0 Preview 3.0 [28608.199.d16.0prev3]
VisualStudio.16.IntPreview/16.0.0-pre.3.0+28608.199.d16.0prev3
Microsoft .NET Framework
Version 4.7.03190

Installed Version: Enterprise

Visual C++ 2019   00435-10000-00000-AA174
Microsoft Visual C++ 2019

Application Insights Tools for Visual Studio Package   9.0.20206.1
Application Insights Tools for Visual Studio

ASP.NET and Web Tools 2019   16.0.12185.18740
ASP.NET and Web Tools 2019

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

Azure App Service Tools v3.0.0   16.0.12185.18740
Azure App Service Tools v3.0.0

Azure Functions and Web Jobs Tools   16.0.12185.18740
Azure Functions and Web Jobs Tools

C# Tools   3.0.0-beta3-19105-04+f9fc5ea40f861ac30e7ad1a322b7517d4af5d47b
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.

Extensibility Message Bus   1.1.77 (master@24013d5)
Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

Microsoft Azure Tools   2.9
Microsoft Azure Tools for Microsoft Visual Studio 0x10 - v2.9.0.0

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

Mono Debugging for Visual Studio   16.0.300 (573eda3)
Support for debugging Mono processes with Visual Studio.

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

Project System Tools   1.0
Tools for working with C#, VisualBasic, and F# projects.

ProjectServicesPackage Extension   1.0
ProjectServicesPackage Visual Studio Extension Detailed Info

ResourcePackage Extension   1.0
ResourcePackage Visual Studio Extension Detailed Info

ResourcePackage Extension   1.0
ResourcePackage Visual Studio Extension Detailed Info

Snapshot Debugging Extension   1.0
Snapshot Debugging Visual Studio Extension Detailed Info

SQL Server Data Tools   16.0.61901.26130
Microsoft SQL Server Data Tools

TypeScript Tools   16.0.10206.2003
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   3.0.0-beta3-19105-04+f9fc5ea40f861ac30e7ad1a322b7517d4af5d47b
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.4 for F# 4.6   16.0.0.0.  Commit Hash: b5c01b8cc65af6381d2dd558ee63a4aa9e0e98d5.
Microsoft Visual F# Tools 10.4 for F# 4.6

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

VisualStudio.Mac   1.0
Mac Extension for Visual Studio

Xamarin   16.0.0.433 (d16-0@949c8f6c5)
Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer   4.17.287 (feb5c9860)
Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin Templates   16.0.330 (e66cdf3)
Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms.

Xamarin.Android SDK   9.1.103.12 (HEAD/7e1c4688)
Xamarin.Android Reference Assemblies and MSBuild support.
    Mono: mono/mono/2018-08@725ba2a2523
    Java.Interop: xamarin/java.interop/d16-0@c987483
    LibZipSharp: grendello/LibZipSharp/master@44de300
    LibZip: nih-at/libzip/rel-1-5-1@b95cf3f
    MXE: xamarin/mxe/xamarin@b9cbb535
    ProGuard: xamarin/proguard/master@905836d
    SQLite: xamarin/sqlite/3.26.0@325e91a
    Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-0@f05c0aa

Xamarin.iOS and Xamarin.Mac SDK   12.6.0.16 (bc9c674)
Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support.

Example Project (If Possible)

PreserveTest.zip

spouliot commented 5 years ago

sounds like the cache is not updated when an assembly is no longer needed (so an old copy might still be present and copied to the .app) c.c. @rolfbjarne

rolfbjarne commented 5 years ago

Yes, this is how we currently behave, we don't keep track of assemblies that aren't included in the build anymore, so we don't know whether they should be deleted or not from the .app during incremental builds.

spouliot commented 5 years ago
  1. rebuild ios app

I think you meant Build (or Run / Debug) but not Rebuild since

A rebuild is required in order for the dll that's no longer referenced in code to not be included with the app

After a rebuild the file is missing. The sample still crash but with a FileNotFoundException (which is fine / expected) instead of

2019-02-12 11:18:51.480 PreserveTest.iOS[31158:15239321] error: Failed to load AOT module '/private/var/containers/Bundle/Application/2D306001-22BA-4F6C-B409-1AEB9FD41DF3/PreserveTest.iOS.app/ExtraLibrary.dll.so' in aot-only mode.

It's an old bug and was not an issue since Assembly.Load is not something commonly used (not really needed) with full AOT builds. Also final/submitted builds are generally done from clean builds (different configs) so it likely never happened on release/appstore builds.

Now those assumptions are changing with the interpreter so thanks for noticing and reporting it :)