Fail to new an instance of gRPC.Core.Channel when code run in Partial Trust

17 views
Skip to first unread message

etha...@infor.com

unread,
Sep 24, 2019, 5:17:15 AM9/24/19
to grpc.io
I am trying to use Grpc.Core.Channel call gRPC service. When code run in Partial Trust environment, an error below would pop up.
"Inheritance security rules violated by Type:'Grpc.Core.internal.SafeHandleZeroIsInvalid' Derived types must either match the security accessibility of the base type or be less accessible"

How can I use Channel to call Grpc service on a partial trust environment? if can't, is there another way to call Grpc Service?

Look into gRPC code, a .net class SafeHandle is inherited by SafeHandleZeroIsInvalid. As official document described, for partially trusted code, it’s not allowed. InheritanceDemand of SafeHandle is: "for full trust for inheritors. This member cannot be inherited by partially trusted code." https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.safehandle?view=netframework-4.8

I had a try to create my own class which inherited from SafeHandle. And, I tryed to new an instance of this class. When code run in Partial Trust, the same error pop up. What I am thinking the SafeHandle is the root reason cause this problem.

//the code is super simple, I just try to create a channel on a constructor. public class WriterClient { private Channel _channel; private LoggingCenter _logger; public WriterClient(int port, ILogging logger) { _logger = logger == null? new LoggingCenter(new NullLogger()): new LoggingCenter(logger); //when run in Partial Trust, the code below will throw an exception. _channel = new Channel("127.0.0.1", port, ChannelCredentials.Insecure); }

What I am wanted is to call Grpc service correctly in Partial Trust. Any workaround for it?

Jan Tattermusch

unread,
Sep 24, 2019, 9:10:15 AM9/24/19
to etha...@infor.com, grpc.io

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/67c0f691-6431-4722-951c-2f8dd8b6489b%40googlegroups.com.


--

Jan

Reply all
Reply to author
Forward
0 new messages