Service Fabric error: "Service does not exist"

Service Fabric error: "Service does not exist"

我收到错误 FabricServiceNotFoundException: Service does not exist.,我不知道为什么。我正在创建的服务名称正是它在我的集群中部署的名称。

这是我创建服务的代码:

return ServiceProxy.Create<ICheckoutService>(
                new Uri("fabric:/ECommerce/ECommerce.CheckoutService"),
                new ServicePartitionKey(0));

这是资源管理器视图。服务名称与我的代码匹配。我在使用其他服务时没有问题。

我尝试了完全重启,但我遇到了同样的错误:

  1. 已从集群中删除应用程序
  2. 集群中未配置的类型
  3. 重新启动集群
  4. 重新启动Visual Studio
  5. 重建并部署应用程序

更新

经过测试,我发现错误的发生取决于我通过 API 方法调用服务的顺序。

如果我部署应用程序并调用方法 checkoutget basket,它们会给出 "Service not found" 错误。

但是,如果我先调用其他方法来执行某些更改 (POST),那么它就可以工作……很奇怪吧?这是我的代码库,可以帮助查看代码。

https://github.com/epomatti/azure-servicefabric-productcatalog

在@maf748 的帮助下,我为所有 CLR 异常打开了 "Break When Thrown" 配置,我发现实际的异常不是 "Service does not exist"。

就我而言,我为 Actor 服务保留了以下 auto-generated 方法,该方法将我的状态设置为错误状态,后来在我自己的代码中失败了。

我需要做的就是删除 Visual Studio 从我的方法创建的这个方法,它工作正常。

    /// <summary>
    /// This method is called whenever an actor is activated.
    /// An actor is activated the first time any of its methods are invoked.
    /// </summary>
    protected override Task OnActivateAsync()
    {
        ActorEventSource.Current.ActorMessage(this, "Actor activated.");

        // The StateManager is this actor's private state store.
        // Data stored in the StateManager will be replicated for high-availability for actors that use volatile or persisted state storage.
        // Any serializable object can be saved in the StateManager.
        // For more information, see https://aka.ms/servicefabricactorsstateserialization

        return this.StateManager.TryAddStateAsync("count", 0);
    }