使用 FabricClient API 时常见的异常和错误Common exceptions and errors when working with the FabricClient APIs

FabricClient API 可让群集和应用程序管理员对 Service Fabric 造应用程序、服务或群集执行管理任务。The FabricClient APIs enable cluster and application administrators to perform administrative tasks on a Service Fabric application, service, or cluster. 例如,部署、升级和删除应用程序、检查群集的运行状况或测试服务。For example, application deployment, upgrade, and removal, checking the health a cluster, or testing a service. 应用程序开发人员和群集管理员可以使用 FabricClient API 来开发用于管理 Service Fabric 群集和应用程序的工具。Application developers and cluster administrators can use the FabricClient APIs to develop tools for managing the Service Fabric cluster and applications.

使用 FabricClient 可以执行许多不同类型的操作。There are many different types of operations which can be performed using FabricClient. 由于输入错误、运行时错误或暂时性基础结构问题,每种方法都可能会引发异常或错误。Each method can throw exceptions for errors due to incorrect input, runtime errors, or transient infrastructure issues. 请参阅 API 参考文档,了解特定的方法会引发哪些异常。See the API reference documentation to find which exceptions are thrown by a specific method. 但是,某些异常可能会由许多不同的 FabricClient API 引发。There are some exceptions, however, which can be thrown by many different FabricClient APIs. 下表列出了 FabricClient API 中常见的异常。The following table lists the exceptions that are common across the FabricClient APIs.

异常Exception 引发时机Thrown when
System.Fabric.FabricObjectClosedExceptionSystem.Fabric.FabricObjectClosedException FabricClient 对象处于关闭状态。The FabricClient object is in a closed state. 释放正在使用的 FabricClient 对象,然后实例化新的 FabricClient 对象。Dispose of the FabricClient object you are using and instantiate a new FabricClient object.
System.TimeoutExceptionSystem.TimeoutException 操作超时。OperationTimedOutThe operation timed out. OperationTimedOut is returned when the operation takes more than MaxOperationTimeout to complete.
System.UnauthorizedAccessExceptionSystem.UnauthorizedAccessException 对操作的访问权限检查失败。The access check for the operation failed. 返回了 E_ACCESSDENIED。E_ACCESSDENIED is returned.
System.Fabric.FabricExceptionSystem.Fabric.FabricException 执行操作时发生运行时错误。A runtime error occurred while performing the operation. 任何 FabricClient 方法都可能引发 FabricExceptionErrorCode 属性指明了引发异常的确切原因。Any of the FabricClient methods can potentially throw FabricException, the ErrorCode property indicates the exact cause of the exception. FabricErrorCode 枚举中将定义错误代码。Error codes are defined in the FabricErrorCode enumeration.
System.Fabric.FabricTransientExceptionSystem.Fabric.FabricTransientException 由于某种暂时性错误状态,操作失败。The operation failed due to a transient error condition of some kind. 例如,由于副本的仲裁暂时不可访问,某项操作可能会失败。For example, an operation may fail because a quorum of replicas is temporarily not reachable. 暂时性异常对应于可重试的失败操作。Transient exceptions correspond to failed operations that can be retried.

可能在 FabricException 中返回的某些常见 FabricErrorCode 错误:Some common FabricErrorCode errors that can be returned in a FabricException:

错误Error 条件Condition
CommunicationErrorCommunicationError 通信错误导致操作失败,请重试操作。A communication error caused the operation to fail, retry the operation.
InvalidCredentialTypeInvalidCredentialType 凭据类型无效。The credential type is invalid.
InvalidX509FindTypeInvalidX509FindType X509FindType 无效。The X509FindType is invalid.
InvalidX509StoreLocationInvalidX509StoreLocation X509 存储位置无效。The X509 store location is invalid.
InvalidX509StoreNameInvalidX509StoreName X509 存储名称无效。The X509 store name is invalid.
InvalidX509ThumbprintInvalidX509Thumbprint X509 证书指纹字符串无效。The X509 certificate thumbprint string is invalid.
InvalidProtectionLevelInvalidProtectionLevel 保护级别无效。The protection level is invalid.
InvalidX509StoreInvalidX509Store 无法打开 X509 证书存储。The X509 certificate store cannot be opened.
InvalidSubjectNameInvalidSubjectName 使用者名称无效。The subject name is invalid.
InvalidAllowedCommonNameListInvalidAllowedCommonNameList 公用名字符串列表的格式无效。The format of common name list string is invalid. 应为逗号分隔的列表。It should be a comma-separated list.