public static async Task <SelectedPartition> GetSelectedPartitionStateAsync( FabricClient fabricClient, PartitionSelector partitionSelector, TimeSpan requestTimeout, TimeSpan operationTimeout, CancellationToken cancellationToken) { ThrowIf.Null(partitionSelector, "PartitionSelector"); Guid partitionId = Guid.Empty; Uri serviceName; if (!partitionSelector.TryGetPartitionIdIfNotGetServiceName(out partitionId, out serviceName)) { // Intentionally do not use FabricClientRetryErrors.GetPartitionListFabricErrors. We do not want to retry "service not found". ServicePartitionList partitionsResult = await FabricClientRetryHelper.ExecuteFabricActionWithRetryAsync <ServicePartitionList>( () => fabricClient.QueryManager.GetPartitionListAsync( serviceName, null, default(string), requestTimeout, cancellationToken), operationTimeout, cancellationToken).ConfigureAwait(false); Partition partitionResult = partitionSelector.GetSelectedPartition(partitionsResult.ToArray(), new Random()); partitionId = partitionResult.PartitionInformation.Id; } else { // Validate the partition specified is actually from the service specified. // Intentionally do not use FabricClientRetryErrors.GetPartitionListFabricErrors. We do not want to retry "service not found". ServicePartitionList partitionsResult = await FabricClientRetryHelper.ExecuteFabricActionWithRetryAsync <ServicePartitionList>( () => fabricClient.QueryManager.GetPartitionListAsync( serviceName, null, default(string), requestTimeout, cancellationToken), operationTimeout, cancellationToken).ConfigureAwait(false); var guids = partitionsResult.Select(p => p.PartitionId()).ToList(); if (!guids.Contains(partitionId)) { // There is no partition in the service specified that has a partition with the id specified. throw new FabricException("Partition not found in this service", FabricErrorCode.PartitionNotFound); } } return(new SelectedPartition(serviceName, partitionId)); }