Nullref when calling injected IGrainServiceClient from a FooGrainService
I'm getting a nullref when trying to invoke an injected IBarGrainServiceClient from a FooGrainService. GrainServiceClient.CallingGrainReference is throwing a nullref due to RuntimeContext.Current?.ActivationContext?.Activation being null.
public interface IAService: IGrainService
{
Task Execute();
}
public interface IAServiceClient: IGrainServiceClient<IAService>, IAService
{}
public interface IBService: IGrainService
{
Task Execute();
}
public interface IBServiceClient: IGrainServiceClient<IBService>, IBService
{}
public interface ICService :IGrainService{}
public class CService :GrainService, ICService
{
private readonly IAServiceClient _aService;
private readonly IBServiceClient _bService;
public CService(IAServiceClient aService, IBServiceClient, IGrainIdentity id, Silo silo, ILoggerFactory loggerFactory): base(id, silo, loggerFactory)
{
_aService = aService;
_bService = bService;
}
public override async Task Start()
{
await base.Start();
_timer = this.RegisterTimer(_ => Execute(), null, TimeSpan.Zero, TimeSpan.FromSeconds(30));
}
public override async Task Stop()
{
_timer?.Dispose();
await base.Stop();
}
private async Task Execute() //service execution must be sequential
{
await _aService.Execute(); //throws at GrainServiceClient.GrainService_get
await _bService.Execute();
}
}
Hi, how to you construct CService ? I asked because, GrainServiceClient needs to be called under an activation context for it to work properly. By that I mean, for example, CService is constructed from a grain's DI container. And Execute() is called from a grain's activation context.
@xiazen I think I have a similar problem, could it be possible to get the GrainServiceClient from outside a grain activation context ?
I tried from host.Services.GetService<IMyServiceClient>(); and I get an instance but its GrainService property return null.
@borbmizzet was it the problem on your side ?
@jrouaix to my knowledge GrainServiceClient has to be called inside a grain activation context.
close due to inactivity. Feel free to reopen.