【问题标题】:Catching custom exception with Service Fabric remoting使用 Service Fabric 远程处理捕获自定义异常
【发布时间】:2018-09-24 13:13:52
【问题描述】:

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

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

它有以下段落:

服务 API 抛出的所有远程异常都被发送回 客户端作为 AggregateException。 RemoteExceptions 应该是 DataContract 可序列化的;如果不是,代理 API 会抛出 ServiceException 里面有序列化错误。

我在服务之间共享的 .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 可序列化将不胜感激。

【问题讨论】:

    标签: azure-service-fabric


    【解决方案1】:

    我所要做的就是:

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

    【讨论】:

    • 这对我不起作用,是否缺少其他细节?我仍然得到序列化异常
    猜你喜欢
    • 2017-09-18
    • 2018-05-30
    • 2013-05-28
    • 2021-02-15
    • 1970-01-01
    • 2018-08-17
    • 2017-07-26
    • 2019-01-02
    • 1970-01-01
    相关资源
    最近更新 更多