gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 01:57:02 27 4
gpt4 key购买 nike

以下文档详细介绍了 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com