grpc / grpc/grpc-dotnet

DefaultServiceActivator<T> is not using custom IServiceProvider

Open
#2,530 0 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
C#
Stars
4.5k
Forks
836
Avg merge
6d 3h
Merged PRs (30d)
7

Description

### What version of gRPC and what language are you using?
2.65.0

### What operating system (Linux, Windows,...) and version?
Windows

### What runtime / compiler are you using (e.g. .NET Core SDK version `dotnet --info`)
.NET SDK:
Version: 8.0.400

### What did you do?
I register my custom IServiceProvider in my Asp.NetCore Kestrel server via:

`webApplicationBuilder.Host.UseServiceProviderFactory( new MyCustomServiceProvider( Container ) );`
// Container is a Autofac IContainer instance
(i´m using a hybrid system that combines the microsoft dependency container with a built Autofac.Container)

### What did you expect to see?
DefaultServiceActivator should us the MyCustomServiceProvider to resolve grpc services

### What did you see instead?
DefaultServiceActivator uses a different instance of IServiceProvider (looks like the default microsoft dependency IServiceProvider)

Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs).
on service creation i´m getting following exception:

`System.InvalidOperationException: Unable to resolve service for type 'MyService' while attempting to activate 'OtherService'.
at Microsoft.Extensions.DependencyInjection.ActivatorUtilities.ThrowHelperUnableToResolveService(Type type, Type requiredBy)
at lambda_method4900(Closure, IServiceProvider, Object[])
at Grpc.AspNetCore.Server.Internal.DefaultGrpcServiceActivator1.Create(IServiceProvider serviceProvider)
at Grpc.Shared.Server.UnaryServerMethodInvoker3.Invoke(HttpContext httpContext, ServerCallContext serverCallContext, TRequest request)
--- End of stack trace from previous location ---
at Grpc.AspNetCore.Server.Internal.CallHandlers.UnaryServerCallHandler3.HandleCallAsyncCore(HttpContext httpContext, HttpContextServerCallContext serverCallContext)
at Grpc.AspNetCore.Server.Internal.CallHandlers.ServerCallHandlerBase3.g__AwaitHandleCall|8_0(HttpContextServerCallContext serverCallContext, Method2 method, Task handleCall)`

Contributor guide

Open the contributing guide

Research direction

Start with the DefaultGrpcServiceActivator1.Create entry point named in the stack trace and trace which IServiceProvider reaches service activation. Reproduce the issue with the custom provider setup described in the report; done means gRPC services resolve dependencies from that provider without the shown InvalidOperationException.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.