Reputation: 1456
The following document details exception handling in remoting for Service Fabric (I use V2):
It has the following paragraph:
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.
I have made the following exception, in a .NET Core class library shared between the services:
[DataContract]
public class DuplicateEntityException : Exception
{
public DuplicateEntityException(string message = "Duplicate entity.") : base(message) { }
}
I get the following message after throwing the exception in the called service:
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.
If I just throw Exception
it serializes correctly.
Any help in making my exception class DataContract serializable would be much appreciated.
Upvotes: 3
Views: 1338
Reputation: 1456
All I had to do was:
[Serializable()]
public class DuplicateEntityException : Exception, ISerializable
{
public DuplicateEntityException(string message = "Duplicate entity.") : base(message) { }
public DuplicateEntityException(SerializationInfo info, StreamingContext context) : base(info, context) { }
}
Upvotes: 4