添加Application Insights后,SignalR IHubContext <T>分辨率崩溃

时间:2019-10-13 06:23:32

标签: c# asp.net-core asp.net-core-signalr

有一个ASP.NET Core 2.2 Web应用程序,它使用Unity作为IoC和SignalR。控制器之一使用注入到其构造函数中的方法获取IHubContext的实例。

一切正常,直到我尝试将Application Insights添加到项目中。从那时起,IHubContext的解析失败,并显示一条异常:“没有公共构造函数可用于System.IServiceProvider类型”。

如果我只注释掉SignalR IHubContext分辨率为“ services.AddApplicationInsightsTelemetry();”的那一行,那么

public void ConfigureServices(IServiceCollection services)
{
   services.AddApplicationInsightsTelemetry();
   services
      .AddMvc()          
      .AddApplicationPart(typeof(SynchronizationController).Assembly)
      .AddControllersAsServices()
      .SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

   services.AddSignalR();
}
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: No public constructor is available for type System.IServiceProvider. ---> Unity.Exceptions.InvalidRegistrationException: Exception of type 'Unity.Exceptions.InvalidRegistrationException' was thrown.
   --- End of inner exception stack trace ---
   at Unity.Processors.ConstructorProcessor.<>c.<GetResolver>b__15_1(BuilderContext& c)
   at Unity.Processors.MemberProcessor`2.<>c__DisplayClass8_0.<GetResolver>b__0(BuilderContext& c)
   at Unity.Processors.MemberProcessor`2.<>c__DisplayClass8_0.<GetResolver>b__0(BuilderContext& c)
   at Unity.Processors.MemberProcessor`2.<>c__DisplayClass8_0.<GetResolver>b__0(BuilderContext& c)
   at Unity.Strategies.BuildPlanStrategy.PreBuildUp(BuilderContext& context)
   at Unity.UnityContainer.<>c.<.ctor>b__41_3(BuilderStrategy[] chain, BuilderContext& context)
   at Unity.Builder.BuilderContext.Resolve(Type type, String name, InternalRegistration registration)
   at Unity.Builder.BuilderContext.Resolve(Type type, String name)
   at Unity.Builder.BuilderContext.Resolve(ParameterInfo parameter, Object value)
   at Unity.Processors.ConstructorProcessor.<>c__DisplayClass16_0.<GetResolverDelegate>b__0(BuilderContext& c)
   at Unity.Processors.MemberProcessor`2.<>c__DisplayClass8_0.<GetResolver>b__0(BuilderContext& c)
   at Unity.Processors.MemberProcessor`2.<>c__DisplayClass8_0.<GetResolver>b__0(BuilderContext& c)
   at Unity.Processors.MemberProcessor`2.<>c__DisplayClass8_0.<GetResolver>b__0(BuilderContext& c)
   at Unity.Strategies.BuildPlanStrategy.PreBuildUp(BuilderContext& context)
   at Unity.UnityContainer.<>c.<.ctor>b__41_3(BuilderStrategy[] chain, BuilderContext& context)
   at Unity.Builder.BuilderContext.Resolve(Type type, String name, InternalRegistration registration)
   at Unity.UnityContainer.ResolveEnumerable[TElement](Func`4 resolve, Type generic, String name)+MoveNext()
   at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at Microsoft.Extensions.DependencyInjection.TelemetryConfigurationOptions..ctor(IEnumerable`1 configureOptions)
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

0 个答案:

没有答案