Possibly related to #972
Since Autofac version 4.9.3, I can't inject anymore a SignalR strongly-typed HubContext in the form of IHubContext<Hub, IHub>. I can't reproduce the issue when I'm on version 4.9.2.
Version used:
Stack Trace
Message: This operation is only valid on generic types.
at System.RuntimeType.GetGenericTypeDefinition()
at Autofac.Util.TypeExtensions.ParameterCompatibleWithTypeConstraint(Type parameter, Type constraint) in C:\\projects\\autofac\\src\\Autofac\\Util\\TypeExtensions.cs:line 193
at Autofac.Util.TypeExtensions.<>c__DisplayClass7_1.<IsCompatibleWithGenericParameterConstraints>b__1(Type constraint) in C:\\projects\\autofac\\src\\Autofac\\Util\\TypeExtensions.cs:line 83
at System.Linq.Enumerable.Any[TSource](IEnumerable`1 source, Func`2 predicate)
at Autofac.Util.TypeExtensions.IsCompatibleWithGenericParameterConstraints(Type genericTypeDefinition, Type[] parameters) in C:\\projects\\autofac\\src\\Autofac\\Util\\TypeExtensions.cs:line 81
at Autofac.Features.OpenGenerics.OpenGenericServiceBinder.TryBindServiceType(Service service, IEnumerable`1 configuredOpenGenericServices, Type openGenericImplementationType, Type& constructedImplementationType, Service[]& constructedServices) in C:\\projects\\autofac\\src\\Autofac\\Features\\OpenGenerics\\OpenGenericServiceBinder.cs:line 57
at Autofac.Features.OpenGenerics.OpenGenericRegistrationSource.RegistrationsFor(Service service, Func`2 registrationAccessor)+MoveNext()
at Autofac.Core.Registration.ComponentRegistry.GetInitializedServiceInfo(Service service) in C:\\projects\\autofac\\src\\Autofac\\Core\\Registration\\ComponentRegistry.cs:line 360
at Autofac.Core.Registration.ComponentRegistry.TryGetRegistration(Service service, IComponentRegistration& registration) in C:\\projects\\autofac\\src\\Autofac\\Core\\Registration\\ComponentRegistry.cs:line 128
at Autofac.ResolutionExtensions.TryResolveService(IComponentContext context, Service service, IEnumerable`1 parameters, Object& instance) in C:\\projects\\autofac\\src\\Autofac\\ResolutionExtensions.cs:line 1035
at Autofac.ResolutionExtensions.ResolveOptionalService(IComponentContext context, Service service, IEnumerable`1 parameters) in C:\\projects\\autofac\\src\\Autofac\\ResolutionExtensions.cs:line 814
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.GetService(IServiceProvider sp, Type type, Type requiredBy, Boolean isDefaultParameterRequired)
at lambda_method(Closure , IServiceProvider , Object[] )
at Microsoft.AspNetCore.Mvc.Controllers.ControllerActivatorProvider.<>c__DisplayClass4_0.<CreateActivator>b__0(ControllerContext controllerContext)
at Microsoft.AspNetCore.Mvc.Controllers.ControllerFactoryProvider.<>c__DisplayClass5_0.<CreateControllerFactory>g__CreateController|0(ControllerContext controllerContext)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.InvokeInnerFilterAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeNextResourceFilter()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Rethrow(ResourceExecutedContext context)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeFilterPipelineAsync()
at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.InvokeAsync()
at Microsoft.AspNetCore.Routing.EndpointMiddleware.Invoke(HttpContext httpContext)
at Microsoft.AspNetCore.Routing.EndpointRoutingMiddleware.Invoke(HttpContext httpContext)
at SignalRExample.Api.Middlewares.ErrorHandlingMiddleware.Invoke(HttpContext context) in D:\\Source\\autofac-bug\\SignalRExample.Api\\SignalRExample.Api\\Middlewares\\ErrorHandlingMiddleware.cs:line 35
Sample to reproduce the issue:
https://github.com/ahocquet/autofac-bug.git
Hey @ahocquet, thanks for the detail, this looks like a duplicate of #1006; we have a pending PR for a 4.9.4 release for this that should resolve your issue once 4.9.4 goes out.
If you want to check now that the existing fix does resolve your issue, you can grab the pre-merge fork from https://github.com/alistairjevans/Autofac/tree/v4.9.4, reference that and retry your scenario.
Hi @alistairjevans, sorry I've missed that dup, I was only looking from currently opened issues.
I've tested your fork and it fixes the issue, good job!
No worries, good to know; 4.9.4 has now been released by the way.
Nice, thank you !!
Most helpful comment
Hey @ahocquet, thanks for the detail, this looks like a duplicate of #1006; we have a pending PR for a 4.9.4 release for this that should resolve your issue once 4.9.4 goes out.
If you want to check now that the existing fix does resolve your issue, you can grab the pre-merge fork from https://github.com/alistairjevans/Autofac/tree/v4.9.4, reference that and retry your scenario.