Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with serializing messages with exceptions #1886

Closed
Horusiath opened this issue Apr 15, 2016 · 7 comments
Closed

Problem with serializing messages with exceptions #1886

Horusiath opened this issue Apr 15, 2016 · 7 comments

Comments

@Horusiath
Copy link
Contributor

Default serializer is not able to properly serialize/deserialize messages with exceptions.

.NET version: 4.6.1
Akka.NET version: 1.0.7
Newtonsoft.Json version: 7.0.1

Example

public sealed class Message
{
    public readonly long Id;
    public readonly Exception Reason;

    public Message(long id, Exception reason)
    {
        Id = id;
        Reason = reason;
    }
}

using (var system = ActorSystem.Create("sys"))
{
    var message = new Message(1, new Exception("custom"));
    var serializer = system.Serialization.FindSerializerFor(message);
    var binary = serializer.ToBinary(message);
    var msg = serializer.FromBinary(binary, null); // Error: Unable to cast object of type 'Newtonsoft.Json.Linq.JObject' to type 'Newtonsoft.Json.Linq.JValue'.
}
@akoshelev
Copy link

akoshelev commented Apr 15, 2016

@Horusiath I've also noticed such behavior. Here is some related issues

JamesNK/Newtonsoft.Json#780

#1409 (comment)

@Horusiath
Copy link
Contributor Author

Horusiath commented Jul 17, 2016

Btw. this is bug related specifically to Json.NET - when using Wire serializer, everything works correctly. (see how to setup a Wire serializer).

@alexvaluyskiy
Copy link
Contributor

@Horusiath your example works fine, without SurrogateConverter in JsonSerializerSettings.

@Horusiath Horusiath added this to the 1.5.0 milestone Aug 10, 2016
@alexvaluyskiy alexvaluyskiy modified the milestones: 1.3.0, 1.5.0 Apr 20, 2017
@alexvaluyskiy
Copy link
Contributor

Scala version consists a separate serializer for Throwable https://github.com/akka/akka/blob/master/akka-remote/src/main/scala/akka/remote/serialization/ThrowableSupport.scala

We could do the same, but it would be a bit harder. We could use a serializer based on ISerializable on .NET and reflection based serializer on NetCore 1.x

Or we could create a separate serializer for ActorInitializationException. It it only one system exception, which could be serialized.

@alexvaluyskiy alexvaluyskiy self-assigned this Jul 17, 2017
@alexvaluyskiy
Copy link
Contributor

Partially fixed in #2925 only for system messages.

@Aaronontheweb
Copy link
Member

@Arkatufus can you take on writing a spec for this? There are other open issues related to this one too:

There are proposals and spec ideas from other users on those issues - need to consider their designs and put something together in writing on this issue before we move forward with a PR.

@Aaronontheweb
Copy link
Member

Per #3903 (comment), looks like we've had built-in support for this for some time but haven't been using it consistently outside of remote deployment scenarios. Going to close this issue and focus on #3903 are the primary implementation point for this.

Repository owner moved this from Todo to Done in Akka.NET v1.5 Total Delivery Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

No branches or pull requests

5 participants