以下文档详细介绍了 Service Fabric 远程处理中的异常处理(我使用 V2):
它有以下段落:
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/