Search code examples
c#asp.net.netazure-service-fabric

MethodAccessException when calling into a Service Fabric Actor service


So I'm writing my first actor service and I ran into this error

System.MethodAccessException: Attempt by method 'Microsoft.ServiceFabric.Services.Remoting.Description.InterfaceDescription..ctor(System.String, System.Type, Microsoft.ServiceFabric.Services.Remoting.Description.MethodReturnCheck)' to access method 'Microsoft.ServiceFabric.Services.Common.IdUtil.ComputeId(System.Type)' failed.
   at Microsoft.ServiceFabric.Services.Remoting.Description.InterfaceDescription..ctor(String remotedInterfaceKindName, Type remotedInterfaceType, MethodReturnCheck methodReturnCheck)
   at Microsoft.ServiceFabric.Actors.Remoting.Builder.ActorCodeBuilder.<BuildProxyGenerator>b__5(Type t)
   at System.Linq.Enumerable.WhereSelectListIterator`2.MoveNext()
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at Microsoft.ServiceFabric.Services.Remoting.Builder.ProxyGeneratorBuilder`2.Build(Type proxyInterfaceType, IEnumerable`1 interfaceDescriptions)
   at Microsoft.ServiceFabric.Services.Remoting.Builder.CodeBuilder.Microsoft.ServiceFabric.Services.Remoting.Builder.ICodeBuilder.GetOrBuildProxyGenerator(Type interfaceType)
   at Microsoft.ServiceFabric.Actors.Remoting.Builder.ActorCodeBuilder.GetOrCreateProxyGenerator(Type actorInterfaceType)
   at Microsoft.ServiceFabric.Actors.Client.ActorProxyFactory.CreateActorProxy[TActorInterface](Uri serviceUri, ActorId actorId, String listenerName)
   at Microsoft.ServiceFabric.Actors.Client.ActorProxy.Create[TActorInterface](ActorId actorId, Uri serviceUri, String listenerName)

I have an actor service and a stateless web API service. In the web API controller I'm trying to get an actor handle like so:

var actorServiceProxy = ActorProxy.Create<IPaymentActor>(ActorId.CreateRandom(), new Uri("fabric:/PaymentService/PaymentActorService"));

That's where the exception is thrown. Any ideas why?

EDIT: actor definition included per request. The PaymentInfo object is marked as DataContract FWIW

public interface IPaymentActor : IActor
{
    /// <summary>
    /// TODO: Replace with your own actor method.
    /// </summary>
    /// <returns></returns>
    Task<PaymentInfo> GetPaymentInformation(CancellationToken cancellationToken);

    /// <summary>
    /// TODO: Replace with your own actor method.
    /// </summary>
    /// <param name="count"></param>
    /// <returns></returns>
    Task SetPaymentInformation(PaymentInfo info, CancellationToken cancellationToken);
}

Solution

  • I figured it out.

    Mis-matching Microsoft.ServiceFabric.Actors library references.

    The File > New Project > Service Fabric > Actor Project scaffolding defaulted to v2.4.164 for the package Microsoft.ServiceFabric.Actors.

    However when I went to add a web front end and added that project via NuGet it added the latest (which is v2.5.216 at the time of writing). This manifested itself as a low-level exception in the library during the RPC call. I will point this out to the Service Fabric team and hope they can provide a check with more meaningful error messaging. In the mean time, if you've stumbled upon this error, check for that.