xamarin / Xamarin.Forms

Xamarin.Forms is no longer supported. Migrate your apps to .NET MAUI.
https://aka.ms/xamarin-upgrade
Other
5.64k stars 1.88k forks source link

[Bug] StackOverflowException compiling after transitive dependency version updates #15704

Closed TheXenocide closed 1 year ago

TheXenocide commented 1 year ago

Description

We have a mobile app that has started reporting build failures with no changes to the actual code/mobile projects. The only changes come from transitive dependency updates originating from references to our other solutions which we've been migrating from .NET Core 3.1 to .NET 6. At first glance the behavior appears very similar to what's described in #2550 although I tried downloading that solution and was not able to reproduce the issue reported there.

Environment

This issue happens both in local development environments running Visual Studio as well as on Mac build agents in our CI/CD environment. The CI/CD environment is not running the very latest version, but I also have a Mac for local development which is running the latest.

Show/Hide Visual Studio (local development) info ``` Microsoft Visual Studio Enterprise 2022 Version 17.5.1 VisualStudio.17.Release/17.5.1+33424.131 Microsoft .NET Framework Version 4.8.09032 Installed Version: Enterprise Visual C++ 2022 00476-80000-00000-AA777 Microsoft Visual C++ 2022 ADL Tools Service Provider 1.0 This package contains services used by Data Lake tools ASA Service Provider 1.0 ASP.NET and Web Tools 17.5.317.37931 ASP.NET and Web Tools AttachToAllTheThings 1.0 AttachToAllTheThings Visual Studio Package Detailed Info Azure App Service Tools v3.0.0 17.5.317.37931 Azure App Service Tools v3.0.0 Azure Data Lake Tools for Visual Studio 2.6.5000.0 Microsoft Azure Data Lake Tools for Visual Studio Azure Functions and Web Jobs Tools 17.5.317.37931 Azure Functions and Web Jobs Tools Azure Stream Analytics Tools for Visual Studio 2.6.5000.0 Microsoft Azure Stream Analytics Tools for Visual Studio C# Tools 4.5.0-6.23123.11+271ccd71554f7d28d2f90551aafd0bdeb5d327aa 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.4.3 (main@2a4517a) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration. File Icons 2.7 Adds icons for files that are not recognized by Solution Explorer Markdown Editor v2 2.0.132 A full featured Markdown editor with live preview and syntax highlighting. Supports GitHub flavored Markdown. Microsoft Azure Hive Query Language Service 2.6.5000.0 Language service for Hive query Microsoft Azure Stream Analytics Language Service 2.6.5000.0 Language service for Azure Stream Analytics Microsoft Azure Tools for Visual Studio 2.9 Support for Azure Cloud Services projects Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines Mono Debugging for Visual Studio 17.5.9 (11975e6) Support for debugging Mono processes with Visual Studio. NuGet Package Manager 6.5.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/ PowerShell Pro Tools for Visual Studio 1.0 A set of tools for developing and debugging PowerShell scripts and modules in Visual Studio. Project System Tools 1.0 Tools for working with C#, VisualBasic, and F# projects. Razor (ASP.NET Core) 17.5.2.2307502+8b3141d86b738daf2ca3ed9c15b12513071fc676 Provides languages services for ASP.NET Core Razor. SQL Server Data Tools 17.2.40118.0 Microsoft SQL Server Data Tools SQL Server Reporting Services 16.0.20243.0 Microsoft SQL Server Reporting Services Designers Version 16.0.20243.0 Syntax Visualizer 1.0 An extension for visualizing Roslyn SyntaxTrees. TFS Source Control Explorer Extension 1.0 Visual Studio Extension for Team Foundation Server Source Control Explorer ToolWindowHostedEditor 1.0 Hosting json editor into a tool window TypeScript Tools 17.0.20105.2003 TypeScript Tools for Microsoft Visual Studio Viasfora 4.4.212 Add color to your Visual Studio editor! Visual Basic Tools 4.5.0-6.23123.11+271ccd71554f7d28d2f90551aafd0bdeb5d327aa 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 17.5.0-beta.23053.5+794b7c259d9646a7eb685dad865aa27da7940a21 Microsoft Visual F# Tools Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio. Visual Studio Spell Check Everywhere VSSpellCheckEverywhere An extension that enables spell checking within any Visual Studio file editor or tool window that uses WPF text boxes. https://GitHub.com/EWSoftware/VSSpellChecker Visual Studio Spell Checker VSSpellChecker An editor extension that checks the spelling of comments, strings, and plain text as you type or interactively with tool windows. https://GitHub.com/EWSoftware/VSSpellChecker VisualStudio.DeviceLog 1.0 Information about my package VisualStudio.Mac 1.0 Mac Extension for Visual Studio VSPackage Extension 1.0 VSPackage Visual Studio Extension Detailed Info WiX Toolset Visual Studio Extension 1.0.0.22 WiX Toolset Visual Studio Extension version 1.0.0.22 Copyright (c) .NET Foundation and contributors. All rights reserved. Xamarin 17.5.0.173 (d17-5@33e727c) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android. Xamarin Designer 17.5.3.46 (remotes/origin/d17-5@e4dd80b2bb) Visual Studio extension to enable Xamarin Designer tools in Visual Studio. Xamarin Templates 17.5.41 (ba80d05) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms. Xamarin.Android SDK 13.2.0.0 (d17-5/797e2e1) Xamarin.Android Reference Assemblies and MSBuild support. Mono: 6dd9def Java.Interop: xamarin/java.interop/main@149d70fe SQLite: xamarin/sqlite/3.40.0@fdc1e34 Xamarin.Android Tools: xamarin/xamarin-android-tools/main@9f02d77 Xamarin.iOS and Xamarin.Mac SDK 16.2.0.5 (7738c90c9) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support. ```
Show/Hide Visual Studio for Mac (CI/CD environment) info ``` Visual Studio Community 2022 for Mac Preview Version 17.3 Preview (17.3 build 1038) Installation UUID: 0c061079-f1bb-4a7f-a0da-c54b26390b22 Runtime .NET 6.0.5 (64-bit) Architecture: Arm64 Roslyn (Language Service) 4.3.0-2.22307.14+b91fc5b06135deb5bd72c105a1b96ce278ad6beb NuGet Version: 6.0.0.262 .NET SDK (Arm64) SDK: /usr/local/share/dotnet/sdk/6.0.301/Sdks SDK Versions: 6.0.301 6.0.202 MSBuild SDKs: /Applications/Visual Studio (Preview).app/Contents/MonoBundle/MSBuild/Current/bin/Sdks .NET SDK (x64) SDK Versions: 3.1.420 3.1.418 .NET Runtime (Arm64) Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 6.0.6 6.0.4 .NET Runtime (x64) Runtime: /usr/local/share/dotnet/x64/dotnet Runtime Versions: 6.0.3 5.0.15 3.1.26 3.1.24 3.1.23 Xamarin.Profiler Version: 1.8.0.19 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler Updater Version: 11 Xamarin.Android Version: 12.3.99.95 (Visual Studio Community) Commit: xamarin-android/main/5432886 Android SDK: /Users/svcteamcity/Library/Developer/Xamarin/android-sdk-macosx Supported Android versions: 12.0 (API level 31) 11.0 (API level 30) SDK Command-line Tools Version: 5.0 SDK Platform Tools Version: 31.0.3 SDK Build Tools Version: 30.0.3 Build Information: Mono: dffa5ab Java.Interop: xamarin/java.interop/main@1f27ab55 SQLite: xamarin/sqlite/3.38.5@df4deab Xamarin.Android Tools: xamarin/xamarin-android-tools/main@fc3c2ac Microsoft Build of OpenJDK Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk 11.0.12 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL Eclipse Temurin JDK Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk 1.8.0.302 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL Android SDK Manager Version: 17.2.0.47 Hash: d6dd135 Branch: remotes/origin/dev/tondat/main-menues~3 Build date: 2022-06-17 20:44:58 UTC Android Device Manager Version: 0.0.0.1127 Hash: 4bb4d48 Branch: remotes/origin/dev/tondat/main-1536295~1 Build date: 2022-06-17 20:44:58 UTC Xamarin Designer Version: 17.3.0.110 Hash: 01d90a6c4 Branch: remotes/origin/d17-3 Build date: 2022-06-17 20:44:52 UTC Apple Developer Tools Xcode 13.3 (20102) Build 13E113 Xamarin.Mac Version: 8.10.0.5 (Visual Studio Community) Hash: 96b3edb6d Branch: d17-2 Build date: 2022-05-18 07:32:06-0400 Xamarin.iOS Version: 15.10.0.5 (Visual Studio Community) Hash: 96b3edb6d Branch: d17-2 Build date: 2022-05-18 07:32:07-0400 Build Information Release ID: 1703001038 Git revision: ab015cef741e20e3cc212648659ecbd4ed089d5a Build date: 2022-06-17 20:41:33+00 Build branch: release-17.3 Build lane: release-17.3 Operating System Mac OS X 12.3.1 Darwin 21.4.0 Darwin Kernel Version 21.4.0 Fri Mar 18 00:47:26 PDT 2022 root:xnu-8020.101.4~15/RELEASE_ARM64_T8101 arm64 ```

Build Logs

I'm creating a Visual Studio feedback ticket to upload logs which may contain sensitive/proprietary information and will link it here, but this is a stack trace extracted from the Mac build agent log which hopefully might help others searching, though it's worth noting that the Visual Studio build output doesn't include this text:

(_LinkAssembliesShrink target) -> 
/Library/Frameworks/Mono.framework/External/xbuild/Xamarin/Android/Xamarin.Android.Legacy.targets(648,5): error XALNK7016: System.StackOverflowException: The requested operation caused a stack overflow.
   at System.Collections.Generic.Dictionary`2[TKey,TValue].FindEntry (TKey key) <0x11faacfa0 + 0x00007> in <3f6d2a84456e45e092f879821e86b209>:0  
   at System.Collections.Generic.Dictionary`2[TKey,TValue].TryGetValue (TKey key, TValue& value) [0x00000] in <3f6d2a84456e45e092f879821e86b209>:0  
   at Mono.Cecil.TypeDefinitionCollection.GetType (System.String namespace, System.String name) [0x0000d] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ModuleDefinition.GetType (System.String namespace, System.String name) [0x0000c] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.GetTypeDefinition (Mono.Cecil.ModuleDefinition module, Mono.Cecil.TypeReference type) [0x00015] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.GetType (Mono.Cecil.ModuleDefinition module, Mono.Cecil.TypeReference reference) [0x00000] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.Resolve (Mono.Cecil.TypeReference type) [0x00057] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ModuleDefinition.Resolve (Mono.Cecil.TypeReference type) [0x00006] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ExportedType.Resolve () [0x0000c] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.GetType (Mono.Cecil.ModuleDefinition module, Mono.Cecil.TypeReference reference) [0x00050] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.Resolve (Mono.Cecil.TypeReference type) [0x00057] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ModuleDefinition.Resolve (Mono.Cecil.TypeReference type) [0x00006] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ExportedType.Resolve () [0x0000c] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.GetType (Mono.Cecil.ModuleDefinition module, Mono.Cecil.TypeReference reference) [0x00050] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.Resolve (Mono.Cecil.TypeReference type) [0x00057] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ModuleDefinition.Resolve (Mono.Cecil.TypeReference type) [0x00006] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ExportedType.Resolve () [0x0000c] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.GetType (Mono.Cecil.ModuleDefinition module, Mono.Cecil.TypeReference reference) [0x00050] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.Resolve (Mono.Cecil.TypeReference type) [0x00057] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ModuleDefinition.Resolve (Mono.Cecil.TypeReference type) [0x00006] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ExportedType.Resolve () [0x0000c] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.GetType (Mono.Cecil.ModuleDefinition module, Mono.Cecil.TypeReference reference) [0x00050] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.Resolve (Mono.Cecil.TypeReference type) [0x00057] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ModuleDefinition.Resolve (Mono.Cecil.TypeReference type) [0x00006] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ExportedType.Resolve () [0x0000c] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.GetType (Mono.Cecil.ModuleDefinition module, Mono.Cecil.TypeReference reference) [0x00050] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.Resolve (Mono.Cecil.TypeReference type) [0x00057] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ModuleDefinition.Resolve (Mono.Cecil.TypeReference type) [0x00006] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ExportedType.Resolve () [0x0000c] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.GetType (Mono.Cecil.ModuleDefinition module, Mono.Cecil.TypeReference reference) [0x00050] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.Resolve (Mono.Cecil.TypeReference type) [0x00057] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ModuleDefinition.Resolve (Mono.Cecil.TypeReference type) [0x00006] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ExportedType.Resolve () [0x0000c] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.GetType (Mono.Cecil.ModuleDefinition module, Mono.Cecil.TypeReference reference) [0x00050] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.Resolve (Mono.Cecil.TypeReference type) [0x00057] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ModuleDefinition.Resolve (Mono.Cecil.TypeReference type) [0x00006] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ExportedType.Resolve () [0x0000c] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.GetType (Mono.Cecil.ModuleDefinition module, Mono.Cecil.TypeReference reference) [0x00050] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.Resolve (Mono.Cecil.TypeReference type) [0x00057] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ModuleDefinition.Resolve (Mono.Cecil.TypeReference type) [0x00006] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ExportedType.Resolve () [0x0000c] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.GetType (Mono.Cecil.ModuleDefinition module, Mono.Cecil.TypeReference reference) [0x00050] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.Resolve (Mono.Cecil.TypeReference type) [0x00057] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ModuleDefinition.Resolve (Mono.Cecil.TypeReference type) [0x00006] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ExportedType.Resolve () [0x0000c] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.GetType (Mono.Cecil.ModuleDefinition module, Mono.Cecil.TypeReference reference) [0x00050] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.Resolve (Mono.Cecil.TypeReference type) [0x00057] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ModuleDefinition.Resolve (Mono.Cecil.TypeReference type) [0x00006] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ExportedType.Resolve () [0x0000c] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.GetType (Mono.Cecil.ModuleDefinition module, Mono.Cecil.TypeReference reference) [0x00050] in <a1877496515440638d95074fc886a18f>:0  
[ ... Redacted Repetition to Fit in Maximum Comment Size ...]
   at Mono.Cecil.MetadataResolver.Resolve (Mono.Cecil.TypeReference type) [0x00057] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ModuleDefinition.Resolve (Mono.Cecil.TypeReference type) [0x00006] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ExportedType.Resolve () [0x0000c] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.GetType (Mono.Cecil.ModuleDefinition module, Mono.Cecil.TypeReference reference) [0x00050] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.Resolve (Mono.Cecil.TypeReference type) [0x00057] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ModuleDefinition.Resolve (Mono.Cecil.TypeReference type) [0x00006] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ExportedType.Resolve () [0x0000c] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.GetType (Mono.Cecil.ModuleDefinition module, Mono.Cecil.TypeReference reference) [0x00050] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.Resolve (Mono.Cecil.TypeReference type) [0x00057] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ModuleDefinition.Resolve (Mono.Cecil.TypeReference type) [0x00006] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ExportedType.Resolve () [0x0000c] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.GetType (Mono.Cecil.ModuleDefinition module, Mono.Cecil.TypeReference reference) [0x00050] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.Resolve (Mono.Cecil.TypeReference type) [0x00057] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ModuleDefinition.Resolve (Mono.Cecil.TypeReference type) [0x00006] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.ExportedType.Resolve () [0x0000c] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.GetType (Mono.Cecil.ModuleDefinition module, Mono.Cecil.TypeReference reference) [0x00050] in <a1877496515440638d95074fc886a18f>:0  
   at Mono.Cecil.MetadataResolver.Resolve (Mono.Cecil.TypeReference type) [0x00057] in <a1877496515440638d95074fc886a18f>:0  
TheXenocide commented 1 year ago

Visual Studio feedback ticket: https://developercommunity.visualstudio.com/t/Xamarin-Compilation-Crashes-with-StackOv/10297995

TheXenocide commented 1 year ago

I've attached a minimal repro StackOverflowRepro.zip and confirmed that the issue is similar to the aforementioned #2550 though in this case the issue is that a newer package release of System.ComponentModel.Composition type forwards System.Lazy<T,TMetaData> to netstandard, while the netstandard facade packaged with Xamarin type forwards that type to System.ComponentModel.Composition, which results in the stack overflow while linking. Because this behavior occurs while linking the provided repro solution must be built in Release mode and, for iOS, must not be set to build for the Simulator and must have a Mac paired while building (if you're trying to repro from Visual Studio anyway).

With help from a support rep we also found this ticket on the Cecil repo, similar to the previous issue, which looks to have been resolved with a custom Cecil assembly resolver (XamlCAssemblyResolver). I suspect a fix for this issue would involve making the resolver more aware of the System/Microsoft assemblies being forwarded to/from as they relate to the libraries contained in the Xamarin BCL and its facades.

Since our code is getting this assembly from a transitive reference and we're pretty confident we don't depend on any code paths that require the latest package for MEF in our mobile codebase, we've worked around this issue by adding an explicit PackageReference to the package and setting ExcludeAssets metadata to all.

Example:

<PackageReference Include="System.ComponentModel.Composition" Version="6.0.0" ExcludeAssets="all" />
jfversluis commented 1 year ago

While it's cool that you're attempting to do this and I hope you succeed, Xamarin.Forms will not support .NET 6 so there will be no official support unfortunately. Good luck with this!