azure-service-fabric - 使用 Service Fabric 远程处理捕获自定义异常

标签 azure-service-fabric

以下文档详细介绍了 Service Fabric 远程处理中的异常处理(我使用 V2):

https://learn.microsoft.com/en-us/azure/service-fabric/service-fabric-reliable-services-communication-remoting#remoting-exception-handling

它有以下段落:

All remote exceptions thrown by the service API are sent back to the client as AggregateException. RemoteExceptions should be DataContract serializable; if they are not, the proxy API throws ServiceException with the serialization error in it.

我在服务之间共享的 .NET Core 类库中创建了以下异常:

[DataContract]
public class DuplicateEntityException : Exception
{
    public DuplicateEntityException(string message = "Duplicate entity.") : base(message) { }
}

在调用的服务中抛出异常后,我收到以下消息:

System.AggregateException: One or more errors occurred. (The exception DuplicateEntityException was unhandled on the service and could not be serialized for transferring to the client.

如果我只是抛出 Exception 它会正确序列化。

如果能帮助我的异常类 DataContract 可序列化,我们将不胜感激。

最佳答案

我所要做的就是:

[Serializable()]
public class DuplicateEntityException : Exception, ISerializable
{
    public DuplicateEntityException(string message = "Duplicate entity.") : base(message) { }

    public DuplicateEntityException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}

关于azure-service-fabric - 使用 Service Fabric 远程处理捕获自定义异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49829495/

相关文章:

c# - Azure Service Fabric Actor 初始化

asp.net-web-api - 托管在 Azure 上的高可用性 Service Fabric Web Api

windows - 传统Windows服务到Service Fabric的迁移

azure-service-fabric - 如何将新节点类型添加到已部署的 Service Fabric 集群?

c# - Azure Service Fabric 服务之间的 Http 通信

c# - 高度可扩展的分布式系统的应用程序/自定义性能计数器日志记录?

azure-service-fabric - 自动缩放 Service Fabric 无状态服务?

c# - 在 Service Fabric 中使用可靠队列而不进行轮询?

visual-studio - 如何从 Visual Studio 将应用程序的多个实例发布到 Service Fabric 群集?

c# - RunAsync 中的生成 actors 抛出 "Interface id ' 183061625 8' is not implemented by object ' CustomActorService.InternalCustomActorService'"