Существует веб-приложение ASP.NET Core 2.2, которое использует Unity в качестве IoC и SignalR. Один из контроллеров получает экземпляр IHubContext, используя инъекцию в его конструктор.
Все работало гладко, пока я не попытался добавить Application Insights в проект. С тех пор разрешение IHubContext завершается сбоем с исключением: «Нет доступного открытого конструктора для типа System.IServiceProvider».
Если я просто закомментирую строку с разрешением "services.AddApplicationInsightsTelemetry();
", SignalR IHubContext станет без исключений.
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)