gRPC IFeatureCollection has been disposed. Object name: 'Collection'

Viewed 401

Using c# gRPC server I have IServerStreamWriter<ClientNotification> ClientNotificationStream to send user notifications

when I'm trying to call ClientNotificationStream.WriteAsync(parameters) I have

System.ObjectDisposedException: 'IFeatureCollection has been disposed.
Object name: 'Collection'.'```

IFeatureCollection has been disposed.
Object name: 'Collection'.. Internal Error:  StackTrace:    at Microsoft.AspNetCore.Http.Features.FeatureReferences`1.ThrowContextDisposed()
   at Microsoft.AspNetCore.Http.Features.FeatureReferences`1.ContextDisposed()
   at Microsoft.AspNetCore.Http.Features.FeatureReferences`1.Fetch[TFeature](TFeature& cached, Func`2 factory)
   at Microsoft.AspNetCore.Http.DefaultHttpContext.get_RequestAborted()
   at Grpc.AspNetCore.Server.Internal.HttpContextServerCallContext.get_CancellationTokenCore()
   at Grpc.Core.ServerCallContext.get_CancellationToken()
   at Grpc.AspNetCore.Server.Internal.HttpContextStreamWriter`1.WriteAsync(TResponse message)
1 Answers

ClientNotificationStream was disposed when I need to do WriteAsync().To fix it I add

WaitHandle.WaitAny(new[] { context.CancellationToken.WaitHandle });

context is ServerCallContext

Related