dotnet / dotnet/aspnetcore

Fatal regression: 6.0.0-preview2 and later break linking for SignalR client

Open
#33,269 32 comments 0 reactions 0 assignees View on GitHub
area-signalr linker-friendliness
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Describe the bug
When Microsoft.AspNetCore.SignalR.Client is updated from 6.0.0-preview1 to preview4 (and possibly preview2 and 3) it no longer works in a Xamarin.Forms (iOS) project if the linker is enabled.

6.6.0-preview1 and earlier versions work fine even when the linker is enabled.

### To Reproduce

1. Install Microsoft.AspNetCore.SignalR.Client 6.0.0-preview4 in a Xamarin.Forms/iOS project.
Note: If you upgrade or downgrade the library, make sure to close down VS For Mac and delete all bin and obj folders as the changes don't seem to be reflected in the build if this is not done.
2. Use the "HubConnectionBuilder" to connect to the SignalR backend
3. Turn on linking ("Link SDKs only")
4. Build and run
5. The app crashes when it's trying to call the HubConnectionBuilder 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.`".

The crash only happens if linking is enabled and the version is 6.0.0-preview4 (I verified that preview1 works, am unsure exactly where it got broken). 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 :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:
```c#
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.

### Exceptions (if any)
```
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 :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
...
```

### Further technical details
```
=== 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
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.