Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/git/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Exception 在服务结构中处理参与者和客户端之间异常的最佳实践_Exception_Actor_Azure Service Fabric - Fatal编程技术网

Exception 在服务结构中处理参与者和客户端之间异常的最佳实践

Exception 在服务结构中处理参与者和客户端之间异常的最佳实践,exception,actor,azure-service-fabric,Exception,Actor,Azure Service Fabric,我想知道在服务结构中,在参与者和客户端之间抛出/处理异常的最佳实践方法是什么 例如,我注意到当一个参与者抛出一个异常时,客户端收到一组嵌套的异常。外部异常类型为System.AggregateException,仅表示“发生了一个或多个错误”。但是,如果深入到实际的内部异常,就会发现无法序列化从Actor抛出的异常 Test method PoCSystem.Test.CommandHandlerTest.CommandHandler_When_ExpectExceptionThrown

我想知道在服务结构中,在参与者和客户端之间抛出/处理异常的最佳实践方法是什么

例如,我注意到当一个参与者抛出一个异常时,客户端收到一组嵌套的异常。外部异常类型为System.AggregateException,仅表示“发生了一个或多个错误”。但是,如果深入到实际的内部异常,就会发现无法序列化从Actor抛出的异常

    Test method PoCSystem.Test.CommandHandlerTest.CommandHandler_When_ExpectExceptionThrown threw exception: 
System.AggregateException: One or more errors occurred. ---> System.AggregateException: One or more errors occurred. ---> 
System.AggregateException: One or more errors occurred. ---> System.ServiceModel.FaultException`1[System.ServiceModel.ExceptionDetail]: 
Type 'PoCActor.Interfaces.ConcurrencyException' cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute.  If the type is a collection, consider marking it with the CollectionDataContractAttribute.  See the Microsoft .NET Framework documentation for other supported types.
如果随后使用DataContract和DataMember属性标记异常,则异常会抱怨它与序列化不兼容


在服务结构中处理错误的最佳方法是什么?

考虑使用老式的.net序列化功能。从visual studio内置的“异常”代码段:

[Serializable]
public class MyException : Exception
{
    public MyException() { }
    public MyException(string message) : base(message) { }
    public MyException(string message, Exception inner) : base(message, inner) { }
    protected MyException(
      System.Runtime.Serialization.SerializationInfo info,
      System.Runtime.Serialization.StreamingContext context)
        : base(info, context) { }
}

最好是抛出FaultException而不是自定义异常,然后只需创建一个用DataContract标记的类ConcurrencyFault,并用catch(FaultException ex)捕获它