【发布时间】:2018-09-24 13:13:52
【问题描述】:
以下文档详细介绍了 Service Fabric(我使用 V2)远程处理中的异常处理:
它有以下段落:
服务 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 可序列化将不胜感激。
【问题讨论】: