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.49k stars 515 forks source link

Fatal regression: Latest version bundled with VS For Mac breaks linking for SignalR client #11812

Closed Tommigun1980 closed 3 years ago

Tommigun1980 commented 3 years ago

When VS For Mac is updated to the latest stable version (8.10), Microsoft.AspNetCore.SignalR.Client no longer works in a Xamarin.Forms (iOS) project if the linker is enabled. Microsoft.AspNetCore.SignalR.Client version doesn't seem to matter, I tried 6.0.0-preview4, 6.0.0-preview3, and 5.0.6. Everything was working properly until VS For Mac was updated and it updated Mono/Xamarin-macios.

Because of this I also filed the bug report at https://github.com/mono/mono/issues/21093 and https://github.com/dotnet/aspnetcore/issues/33269 as I don't know whether it belongs in the ASP.Net/SignalR, Xamarin-MacIOS or Mono issues category.

Steps to Reproduce

  1. Update to the latest version of VS For Mac (8.10)
  2. Add Microsoft.AspNetCore.SignalR.Client (version doesn't seem to matter)
  3. Use its "HubConnectionBuilder" to connect to the SignalR backend
  4. Turn on linking ("Link SDKs only")
  5. Build and run
  6. The app crashes when it's trying to run the code in the SignalR client library, with the error "System.InvalidOperationException: A suitable constructor for type 'Microsoft.Extensions.Options.UnnamedOptionsManager'1[Microsoft.AspNetCore.Http.Connections.Client.HttpConnectionOptions]' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.".

Please note that this started to happen only when I updated VS For Mac (8.10), and that the crash only happens if linking is enabled. The full stack trace is as follows:

System.InvalidOperationException: A suitable constructor for type 'Microsoft.Extensions.Options.UnnamedOptionsManager'1[Microsoft.AspNetCore.Http.Connections.Client.HttpConnectionOptions]' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite (Microsoft.Extensions.DependencyInjection.ServiceLookup.ResultCache lifetime, System.Type serviceType, System.Type implementationType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x00021] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateOpenGeneric (Microsoft.Extensions.DependencyInjection.ServiceDescriptor descriptor, System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain, System.Int32 slot, System.Boolean throwOnConstraintViolation) [0x0004a] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateOpenGeneric (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x00025] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x0003a] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x00010] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites (System.Type implementationType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain, System.Reflection.ParameterInfo[] parameters, System.Boolean throwIfCallSiteNotFound) [0x00016] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite (Microsoft.Extensions.DependencyInjection.ServiceLookup.ResultCache lifetime, System.Type serviceType, System.Type implementationType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x00050] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact (Microsoft.Extensions.DependencyInjection.ServiceDescriptor descriptor, System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain, System.Int32 slot) [0x00073] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x00018] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x0002e] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x00010] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.CreateServiceAccessor (System.Type serviceType) [0x0000c] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at System.Collections.Concurrent.ConcurrentDictionary'2[TKey,TValue].GetOrAdd (TKey key, System.Func'2[T,TResult] valueFactory) [0x00034] in <cf60a21f6a4543e5a30e3c6ae6742e37>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope serviceProviderEngineScope) [0x00013] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService (System.Type serviceType) [0x00008] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService (System.Type serviceType) [0x00000] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T] (System.IServiceProvider provider) [0x0000e] in <44acc522f4fc4e959fecc254d3efdbfc>:0
  at Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilder.Build () [0x00025] in <207ee6dcc63548f6a7de0cf3bd6154d5>:0
  at MyProject.Services.ServerConnectionService.CreateConnection () [0x0000c] in /Users/tommikiviniemi/Projects/myproject/MyApp/Services/ServerConnectionService.cs:133
...

The code it complains about, HubConnectionBuilder.Build, will crash even with an empty connection builder:

return new HubConnectionBuilder().Build();

Please note that this is a Xamarin.Forms project, in case it has any bearing on anything.

It goes without saying that this is a catastrophic failure and I'd really appreciate a fix. Thank you.

Expected Behavior

When linking is enabled, it should still work.

Actual Behavior

When the incorrectly stripped code is run, the app crashes.

Environment

=== Visual Studio Community 2019 for Mac ===

Version 8.10 (build 1773)
Installation UUID: c397ff94-0681-4a22-9972-062a757ab635
    GTK+ 2.24.23 (Raleigh theme)
    Xamarin.Mac 6.18.0.23 (d16-6 / 088c73638)

    Package version: 612000140

=== Mono Framework MDK ===

Runtime:
    Mono 6.12.0.140 (2020-02/51d876a041e) (64-bit)
    Package version: 612000140

=== Roslyn (Language Service) ===

3.10.0-3.21251.8+4c32f5e4e9c0828a94fd4d1c9c0994082c85aaf3

=== NuGet ===

Version: 5.9.0.7134

=== .NET Core SDK ===

SDK: /usr/local/share/dotnet/sdk/5.0.203/Sdks
SDK Versions:
    5.0.203
    5.0.202
    3.1.409
    3.1.408
MSBuild SDKs: /Applications/Visual Studio.app/Contents/Resources/lib/monodevelop/bin/MSBuild/Current/bin/Sdks

=== .NET Core Runtime ===

Runtime: /usr/local/share/dotnet/dotnet
Runtime Versions:
    5.0.6
    5.0.5
    3.1.15
    3.1.14

=== .NET Core 3.1 SDK ===

SDK: 3.1.409

=== Xamarin.Profiler ===

Version: 1.6.15.68
Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler

=== Updater ===

Version: 11

=== Apple Developer Tools ===

Xcode 12.5 (18205)
Build 12E262

=== Xamarin.Mac ===

Xamarin.Mac not installed. Can't find /Library/Frameworks/Xamarin.Mac.framework/Versions/Current/Version.

=== Xamarin.iOS ===

Version: 14.20.0.1 (Visual Studio Community)
Hash: fe0e2c518
Branch: d16-10
Build date: 2021-05-19 08:15:56-0400

=== Xamarin.Android ===

Version: 11.3.0.1 (Visual Studio Community)
Commit: xamarin-android/d16-10/22fc2b3
Android SDK: /Users/tommikiviniemi/Library/Developer/Xamarin/android-sdk-macosx
    Supported Android versions:
        None installed

SDK Tools Version: 26.1.1
SDK Platform Tools Version: 30.0.4
SDK Build Tools Version: 30.0.2

Build Information: 
Mono: b4a3858
Java.Interop: xamarin/java.interop/d16-10@f39db25
ProGuard: Guardsquare/proguard/v7.0.1@912d149
SQLite: xamarin/sqlite/3.35.4@85460d3
Xamarin.Android Tools: xamarin/xamarin-android-tools/d16-10@c5732a0

=== Microsoft OpenJDK for Mobile ===

Java SDK: /Users/tommikiviniemi/Library/Developer/Xamarin/jdk/microsoft_dist_openjdk_1.8.0.25
1.8.0-25
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Android SDK Manager ===

Version: 16.10.0.12
Hash: e240b8c
Branch: remotes/origin/d16-10
Build date: 2021-05-13 17:01:38 UTC

=== Android Device Manager ===

Version: 16.10.0.14
Hash: e340248
Branch: remotes/origin/d16-10
Build date: 2021-05-13 17:01:56 UTC

=== Xamarin Designer ===

Version: 16.10.0.117
Hash: 249267d55
Branch: remotes/origin/d16-10
Build date: 2021-05-24 21:27:04 UTC

=== Build Information ===

Release ID: 810001773
Git revision: 56d63e5691f86f863cfaed823a5a8fe430e1aaa9
Build date: 2021-05-28 11:21:28-04
Build branch: release-8.10

=== Operating System ===

Mac OS X 10.16.0
Darwin 20.5.0 Darwin Kernel Version 20.5.0
    Sat May  8 05:10:33 PDT 2021
    root:xnu-7195.121.3~9/RELEASE_X86_64 x86_64

Stacktrace

System.InvalidOperationException: A suitable constructor for type 'Microsoft.Extensions.Options.UnnamedOptionsManager'1[Microsoft.AspNetCore.Http.Connections.Client.HttpConnectionOptions]' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite (Microsoft.Extensions.DependencyInjection.ServiceLookup.ResultCache lifetime, System.Type serviceType, System.Type implementationType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x00021] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateOpenGeneric (Microsoft.Extensions.DependencyInjection.ServiceDescriptor descriptor, System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain, System.Int32 slot, System.Boolean throwOnConstraintViolation) [0x0004a] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateOpenGeneric (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x00025] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x0003a] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x00010] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites (System.Type implementationType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain, System.Reflection.ParameterInfo[] parameters, System.Boolean throwIfCallSiteNotFound) [0x00016] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite (Microsoft.Extensions.DependencyInjection.ServiceLookup.ResultCache lifetime, System.Type serviceType, System.Type implementationType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x00050] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact (Microsoft.Extensions.DependencyInjection.ServiceDescriptor descriptor, System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain, System.Int32 slot) [0x00073] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x00018] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x0002e] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x00010] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.CreateServiceAccessor (System.Type serviceType) [0x0000c] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at System.Collections.Concurrent.ConcurrentDictionary'2[TKey,TValue].GetOrAdd (TKey key, System.Func'2[T,TResult] valueFactory) [0x00034] in <cf60a21f6a4543e5a30e3c6ae6742e37>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope serviceProviderEngineScope) [0x00013] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService (System.Type serviceType) [0x00008] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService (System.Type serviceType) [0x00000] in <5c5c2d1e15f743cd9b15d3422c0b5a91>:0
  at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T] (System.IServiceProvider provider) [0x0000e] in <44acc522f4fc4e959fecc254d3efdbfc>:0
  at Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilder.Build () [0x00025] in <207ee6dcc63548f6a7de0cf3bd6154d5>:0
  at MyProject.Services.ServerConnectionService.CreateConnection () [0x0000c] in /Users/tommikiviniemi/Projects/myproject/MyApp/Services/ServerConnectionService.cs:133
...
Tommigun1980 commented 3 years ago

After downgrading the Microsoft.AspNetCore.SignalR.Client package from 6.0.0-preview4 to preview1 again, and then cleaning the project and deleting bin and obj folders, things started to work again. So https://github.com/dotnet/aspnetcore/issues/33269 seems to be the correct destination for this report, and it breaking after the update of VS was just coincidental. I will file a separate bug report about VS For Mac sometimes requiring deleting said folders before package changes are reflected, and will follow up on the issue in the ASP.NET Core repo.

Closing this report now that the root cause was found. Thank you.

Tommigun1980 commented 3 years ago

Closing.