The Wayback Machine - https://web.archive.org/web/20210604014626/https://github.com/dotnet/aspnetcore/issues/33269
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Tommigun1980 opened this issue Jun 4, 2021 · 0 comments

Comments

@Tommigun1980
Copy link

@Tommigun1980 Tommigun1980 commented Jun 4, 2021

Describe the bug

When VS For Mac is updated to the latest stable version (8.10), Microsoft.AspNetCore.SignalR.Client no longer works 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.

Because of this I also filed the bug report at mono/mono#21093 as I don't know whether it belongs here or in the mono issues category.

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, looks as follows:

            return new HubConnectionBuilder()
                .AddJsonProtocol(options =>
                {
                    options.PayloadSerializerOptions.PropertyNamingPolicy = null;
                })
                .WithUrl(new Uri($"{AppSettingsService.GetAppSettings().AzureBackendUrl}/ConnectionHub"), options =>
                {
                    // TODO: use real authorization flow; was using this for passing our session but signalr service doesn't forward it properly:
                    //options.AccessTokenProvider = () => Task.FromResult(this.AccountService.GetAccessToken().ToString());
                    // so using this instead. can't use HttpRequestHeader.Authorization as it's used internally and overwritten by signalr service
                    options.Headers[$"X-Connection-{System.Net.HttpRequestHeader.Authorization}"] = this.AccountService.GetSerializedAccessToken().ToString();

                    // TODO: disabling sockets for now as communication is one-way, server-to-client push only
                    options.Transports = HttpTransportType.ServerSentEvents | HttpTransportType.LongPolling;
                })
                .ConfigureLogging(logging =>
                {
                    logging.AddConsole();
#if DEBUG
                    logging.SetMinimumLevel(LogLevel.Information);
#else
                    logging.SetMinimumLevel(LogLevel.Warning);
#endif
                })
                .WithAutomaticReconnect() // TODO: handle infinite retries - https://docs.microsoft.com/en-us/aspnet/core/signalr/dotnet-client?view=aspnetcore-3.1&tabs=visual-studio
                .Build();

I am quite sure that any call to HubConnectionBuilder would crash it when the linker is enabled.
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 <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
...

Further technical details

netstandard2.1 true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant