【问题标题】:MethodAccessException when calling into a Service Fabric Actor service调用 Service Fabric Actor 服务时出现 MethodAccessException
【发布时间】:2017-09-02 06:04:08
【问题描述】:

所以我正在编写我的第一个演员服务,我遇到了这个错误

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)

我有一个参与者服务和一个无状态 Web API 服务。在网络 API 控制器中,我试图像这样获得一个演员句柄:

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

这就是引发异常的地方。任何想法为什么?

编辑:每个请求都包含参与者定义。 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);
}

【问题讨论】:

  • 你的actor接口是如何定义的?可以发一下吗?
  • 完成。如前所述,PaymentInfo 对象及其属性被标记为 DataContract 用于序列化目的。

标签: c# asp.net .net azure-service-fabric


【解决方案1】:

我想通了。

不匹配的 Microsoft.ServiceFabric.Actors 库引用。

Microsoft.ServiceFabric.Actors 包的文件 > 新项目 > Service Fabric > Actor 项目脚手架默认为 v2.4.164。

但是,当我去添加 Web 前端并通过 NuGet 添加该项目时,它添加了最新版本(在撰写本文时为 v2.5.216)。这表现为 RPC 调用期间库中的低级异常。我将向 Service Fabric 团队指出这一点,并希望他们能够提供更有意义的错误消息检查。同时,如果您偶然发现了这个错误,请检查一下。

【讨论】:

    【解决方案2】:

    是的,没错。 Microsoft.ServiceFabric.Services.Remoting 是在 2.5.216 版本中添加的,它依赖于 Microsoft.ServiceFabric.Services.2.5.216 nuget 包。所以一旦你升级了所有的 nuget 包,它就可以正常工作了。

    【讨论】:

      猜你喜欢
      • 2017-01-31
      • 2019-11-07
      • 1970-01-01
      • 2018-08-27
      • 2016-10-30
      • 2016-03-11
      • 2018-01-11
      • 2019-04-07
      • 1970-01-01
      相关资源
      最近更新 更多