#c# #uwp #uwp-xaml #asp.net-core-signalr
#c# #uwp #uwp-xaml #asp.net-core-signalr
Вопрос:
Итак, мы столкнулись с ошибкой, которую не можем решить. Мы используем SignalR (Core), чтобы сервер отправлял данные подключенным клиентам. Сервер — это API с .Net Core 3.1, а клиенты — клиенты UWP. В режиме отладки все работает нормально, но когда мы создаем выпуск нашего клиента, соединение SignalR не удалось.
Вот код подключения :
var connectUrl = await ControllerManager.Instance.GetAsync<string>($"Signalr/connectionurl");
var token = ControllerManager.Instance.EchinoBearerToken;
_chatHubConnection = new HubConnectionBuilder()
.WithUrl($"{connectUrl}/signalr/chathub", options => {
options.AccessTokenProvider = () => Task.FromResult(token);
})
.Build();
Ошибка :
Microsoft.AspNetCore.HttpConnections.Client.HttpConnectionOptions on Microsoft.Extensions.Options.OptionsManager [TOptions] violates the constraint of type TOptions
Parameter name : GenericArguments[0[
И вот трассировка стека сбоя:
at Internal.Reflection.Execution.ConstraintValidator.EnsureSatisfiesClassConstraints(Type[] typeParameters, Type[] typeArguments, Object definition, SigTypeContext typeContext) in f:ddndpfxcoreCoreRTsrcSystem.Private.Reflection.ExecutionsrcInternalReflectionExecutionTypeLoaderConstraintValidator.cs:line 86
at Internal.Reflection.Execution.ConstraintValidator.EnsureSatisfiesClassConstraints(Type typeDefinition, Type[] typeArguments) in f:ddndpfxcoreCoreRTsrcSystem.Private.Reflection.ExecutionsrcInternalReflectionExecutionTypeLoaderConstraintValidator.cs:line 96
at Internal.Reflection.Execution.ExecutionEnvironmentImplementation.TryGetConstructedGenericTypeForComponents(RuntimeTypeHandle genericTypeDefinitionHandle, RuntimeTypeHandle[] genericTypeArgumentHandles, RuntimeTypeHandleamp; runtimeTypeHandle) in f:ddndpfxcoreCoreRTsrcSystem.Private.Reflection.ExecutionsrcInternalReflectionExecutionExecutionEnvironmentImplementation.MappingTables.cs:line 356
at System.Reflection.Runtime.TypeInfos.RuntimeConstructedGenericTypeInfo.GetRuntimeTypeHandleIfAny(RuntimeTypeInfo genericTypeDefinition, RuntimeTypeInfo[] genericTypeArguments) in f:ddndpfxcoreCoreRTsrcSystem.Private.Reflection.CoresrcSystemReflectionRuntimeGeneralTypeUnifier.cs:line 419
at System.Reflection.Runtime.TypeInfos.RuntimeConstructedGenericTypeInfo.GetRuntimeConstructedGenericTypeInfo(RuntimeTypeInfo genericTypeDefinition, RuntimeTypeInfo[] genericTypeArguments) in f:ddndpfxcoreCoreRTsrcSystem.Private.Reflection.CoresrcSystemReflectionRuntimeGeneralTypeUnifier.cs:line 388
at System.Reflection.Runtime.TypeInfos.RuntimeTypeInfo.MakeGenericType(Type[] typeArguments) in f:ddndpfxcoreCoreRTsrcSystem.Private.Reflection.CoresrcSystemReflectionRuntimeTypeInfosRuntimeTypeInfo.cs:line 472
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateOpenGeneric(ServiceDescriptor descriptor, Type serviceType, CallSiteChain callSiteChain, Int32 slot)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateOpenGeneric(Type serviceType, CallSiteChain callSiteChain)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type serviceType, CallSiteChain callSiteChain)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.<>c__DisplayClass7_0.<GetCallSite>b__0(Type type)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(Type serviceType, CallSiteChain callSiteChain)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateArgumentCallSites(Type serviceType, Type implementationType, CallSiteChain callSiteChain, ParameterInfo[] parameters, Boolean throwIfCallSiteNotFound)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite(ResultCache lifetime, Type serviceType, Type implementationType, CallSiteChain callSiteChain)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(ServiceDescriptor descriptor, Type serviceType, CallSiteChain callSiteChain, Int32 slot)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact(Type serviceType, CallSiteChain callSiteChain)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite(Type serviceType, CallSiteChain callSiteChain)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.<>c__DisplayClass7_0.<GetCallSite>b__0(Type type)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.GetCallSite(Type serviceType, CallSiteChain callSiteChain)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.CreateServiceAccessor(Type serviceType)
at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType, ServiceProviderEngineScope serviceProviderEngineScope)
at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService(Type serviceType)
at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T](IServiceProvider provider)
at Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilder.Build()
at Echino.ClientMicrosoftLibrary.SignalR.ClientMessageService.<InitHub>d__8.MoveNext() in C:SourceEchinoEchino-branch-VanillaEchino.ClientMicrosoftLibrarySignalRClientMessageService.cs:line 52
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in f:ddndpfxcoreCoreRTsrcSystem.Private.CoreLibsrcSystemRuntimeExceptionServicesExceptionDispatchInfo.cs:line 63
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in f:ddndpfxcoreCoreRTsrcSystem.Private.CoreLibsharedSystemRuntimeCompilerServicesTaskAwaiter.cs:line 186
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in f:ddndpfxcoreCoreRTsrcSystem.Private.CoreLibsharedSystemRuntimeCompilerServicesTaskAwaiter.cs:line 154
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) in f:ddndpfxcoreCoreRTsrcSystem.Private.CoreLibsharedSystemRuntimeCompilerServicesTaskAwaiter.cs:line 125
at System.Runtime.CompilerServices.TaskAwaiter.GetResult() in f:ddndpfxcoreCoreRTsrcSystem.Private.CoreLibsharedSystemRuntimeCompilerServicesTaskAwaiter.cs:line 515
at Echino.ClientMicrosoftLibrary.SignalR.ClientMessageService.<Connect>d__9.MoveNext() in C:SourceEchinoEchino-branch-VanillaEchino.ClientMicrosoftLibrarySignalRClientMessageService.cs:line 123
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in f:ddndpfxcoreCoreRTsrcSystem.Private.CoreLibsrcSystemRuntimeExceptionServicesExceptionDispatchInfo.cs:line 63
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in f:ddndpfxcoreCoreRTsrcSystem.Private.CoreLibsharedSystemRuntimeCompilerServicesTaskAwaiter.cs:line 186
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in f:ddndpfxcoreCoreRTsrcSystem.Private.CoreLibsharedSystemRuntimeCompilerServicesTaskAwaiter.cs:line 154
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) in f:ddndpfxcoreCoreRTsrcSystem.Private.CoreLibsharedSystemRuntimeCompilerServicesTaskAwaiter.cs:line 125
at System.Runtime.CompilerServices.TaskAwaiter.GetResult() in f:ddndpfxcoreCoreRTsrcSystem.Private.CoreLibsharedSystemRuntimeCompilerServicesTaskAwaiter.cs:line 515
at Echino.ClientMicrosoftUIComponents.Login.LoginController.<>c.<<OnLoaded>b__9_1>d.MoveNext() in C:SourceEchinoEchino-branch-VanillaEchino.ClientMicrosoftUIComponentsLoginLoginController.xaml.cs:line 157
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() in f:ddndpfxcoreCoreRTsrcSystem.Private.CoreLibsrcSystemRuntimeExceptionServicesExceptionDispatchInfo.cs:line 63
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) in f:ddndpfxcoreCoreRTsrcSystem.Private.CoreLibsharedSystemRuntimeCompilerServicesTaskAwaiter.cs:line 186
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) in f:ddndpfxcoreCoreRTsrcSystem.Private.CoreLibsharedSystemRuntimeCompilerServicesTaskAwaiter.cs:line 154
at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) in f:ddndpfxcoreCoreRTsrcSystem.Private.CoreLibsharedSystemRuntimeCompilerServicesTaskAwaiter.cs:line 125
at System.Runtime.CompilerServices.TaskAwaiter.GetResult() in f:ddndpfxcoreCoreRTsrcSystem.Private.CoreLibsharedSystemRuntimeCompilerServicesTaskAwaiter.cs:line 515
at Echino.ClientMicrosoftUIComponents.Login.LoginController.<OnLoaded>d__9.MoveNext() in C:SourceEchinoEchino-branch-VanillaEchino.ClientMicrosoftUIComponentsLoginLoginController.xaml.cs:line 155
Последнее появление нашего файла в трассировке стека — это ClientMessageService.cs: строка 52. Это вставленный код
Минимальная версия UWP — Windows 10 Fall Creators Update, а целевая версия — 1809 build 17763.
Кто-нибудь может помочь нам решить нашу проблему? Не стесняйтесь запрашивать дополнительную информацию.
Большое спасибо
Комментарии:
1. Вы добавили трассировку стека, но не сообщение об ошибке, пожалуйста, добавьте его.
2. Да, только что понял, что уже редактировал, но спасибо 😉
3. Это похоже на смесь разных версий сборок, убедитесь, что в выпуске есть те же сборки, что и в отладочной сборке.
4. Вы включили возможности uwp client app для частных сетей?
5. @NicoZhu-MSFT Да, он включен