简体   繁体   English

调用Service Fabric Actor服务时出现MethodAccessException

[英]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. 我有一个参与者服务和一个无状态的Web API服务。 In the web API controller I'm trying to get an actor handle like so: 在Web API控制器中,我试图像这样获取actor句柄:

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 PaymentInfo对象被标记为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);
}

Yes that's correct. 对,那是正确的。 Microsoft.ServiceFabric.Services.Remoting is added in 2.5.216 release and it depends on Microsoft.ServiceFabric.Services.2.5.216 nuget package. Microsoft.ServiceFabric.Services.Remoting已添加到2.5.216版本中,并且依赖于Microsoft.ServiceFabric.Services.2.5.216 nuget包。 So once you upgraded all your nuget packages, it worked fine. 因此,一旦您升级了所有nuget软件包,它都可以正常工作。

I figured it out. 我想到了。

Mis-matching Microsoft.ServiceFabric.Actors library references. Microsoft.ServiceFabric.Actors库引用不匹配。

The File > New Project > Service Fabric > Actor Project scaffolding defaulted to v2.4.164 for the package Microsoft.ServiceFabric.Actors. 对于包Microsoft.ServiceFabric.Actors,“文件”>“新建项目”>“ Service Fabric”>“ Actor项目”支架默认为v2.4.164。

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). 但是,当我去添加Web前端并通过NuGet添加该项目时,它添加了最新的(在撰写本文时为v2.5.216)。 This manifested itself as a low-level exception in the library during the RPC call. 这在RPC调用期间表现为库中的低级异常。 I will point this out to the Service Fabric team and hope they can provide a check with more meaningful error messaging. 我将向Service Fabric团队指出这一点,并希望他们可以提供更有意义的错误消息检查。 In the mean time, if you've stumbled upon this error, check for that. 同时,如果您偶然发现了此错误,请检查该错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM