-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Remove restrictions required by netstandard 1.x but available in 2.0 #3790
Changes from 1 commit
a43207d
98680a2
0e52d7a
5d6c75b
587a396
48929a5
b25daa0
bf43ec0
8a2abe8
23a583e
bd0bd38
47a8530
71e1b68
72d6823
d0008b1
b7c7611
0740894
f6a5df8
c8c4d0b
5b584c1
3dfd0c0
6422da1
c34b2a6
d0b5302
5bb8450
e53cc2c
6e33872
bd7e10c
68cc15b
0956e76
0a196e0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,14 +14,15 @@ | |
using Akka.Util.Internal; | ||
using Google.Protobuf; | ||
using System.Runtime.Serialization; | ||
using Akka.Remote.Serialization.Proto.Msg; | ||
|
||
namespace Akka.Remote.Serialization | ||
{ | ||
internal class ExceptionSupport | ||
{ | ||
private readonly WrappedPayloadSupport _wrappedPayloadSupport; | ||
private const BindingFlags All = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public; | ||
private HashSet<string> DefaultProperties = new HashSet<string> | ||
private readonly HashSet<string> _defaultProperties = new HashSet<string> | ||
{ | ||
"ClassName", | ||
"Message", | ||
|
@@ -66,7 +67,7 @@ internal Exception ExceptionFromProto(Proto.Msg.ExceptionData proto) | |
return ExceptionFromProtoNet(proto); | ||
} | ||
|
||
private FormatterConverter DefaultFormatterConverter = new FormatterConverter(); | ||
private readonly FormatterConverter _defaultFormatterConverter = new FormatterConverter(); | ||
|
||
public Proto.Msg.ExceptionData ExceptionToProtoNet(Exception exception) | ||
{ | ||
|
@@ -84,14 +85,22 @@ public Proto.Msg.ExceptionData ExceptionToProtoNet(Exception exception) | |
message.InnerException = ExceptionToProto(exception.InnerException); | ||
|
||
var serializable = exception as ISerializable; | ||
var serializationInfo = new SerializationInfo(exceptionType, DefaultFormatterConverter); | ||
var serializationInfo = new SerializationInfo(exceptionType, _defaultFormatterConverter); | ||
serializable.GetObjectData(serializationInfo, new StreamingContext()); | ||
|
||
foreach (var info in serializationInfo) | ||
{ | ||
if (DefaultProperties.Contains(info.Name)) continue; | ||
var preparedValue = _wrappedPayloadSupport.PayloadToProto(info.Value); | ||
message.CustomFields.Add(info.Name, preparedValue); | ||
if (_defaultProperties.Contains(info.Name)) continue; | ||
if (info.Value is Exception exceptionValue) | ||
{ | ||
var exceptionPayload = ExceptionToProto(exceptionValue); | ||
var preparedValue = _wrappedPayloadSupport.PayloadToProto(exceptionPayload); | ||
message.CustomFields.Add(info.Name, preparedValue); | ||
} else | ||
{ | ||
var preparedValue = _wrappedPayloadSupport.PayloadToProto(info.Value); | ||
message.CustomFields.Add(info.Name, preparedValue); | ||
} | ||
} | ||
|
||
return message; | ||
|
@@ -104,22 +113,25 @@ public Exception ExceptionFromProtoNet(Proto.Msg.ExceptionData proto) | |
|
||
Type exceptionType = Type.GetType(proto.TypeName); | ||
|
||
var serializationInfo = new SerializationInfo(exceptionType, DefaultFormatterConverter); | ||
var serializationInfo = new SerializationInfo(exceptionType, _defaultFormatterConverter); | ||
|
||
serializationInfo.AddValue("ClassName", proto.TypeName); | ||
serializationInfo.AddValue("Message", proto.Message); | ||
serializationInfo.AddValue("StackTraceString", proto.StackTrace); | ||
serializationInfo.AddValue("Source", proto.Source); | ||
serializationInfo.AddValue("Message", ValueOrNull(proto.Message)); | ||
serializationInfo.AddValue("StackTraceString", ValueOrNull(proto.StackTrace)); | ||
serializationInfo.AddValue("Source", ValueOrNull(proto.Source)); | ||
serializationInfo.AddValue("InnerException", ExceptionFromProto(proto.InnerException)); | ||
serializationInfo.AddValue("HelpURL", string.Empty); | ||
serializationInfo.AddValue("RemoteStackTraceString", string.Empty); | ||
serializationInfo.AddValue("RemoteStackTraceString", null); | ||
serializationInfo.AddValue("RemoteStackIndex", 0); | ||
serializationInfo.AddValue("ExceptionMethod", string.Empty); | ||
serializationInfo.AddValue("ExceptionMethod", null); | ||
serializationInfo.AddValue("HResult", int.MinValue); | ||
|
||
foreach (var field in proto.CustomFields) | ||
{ | ||
serializationInfo.AddValue(field.Key, _wrappedPayloadSupport.PayloadFrom(field.Value)); | ||
var payload = _wrappedPayloadSupport.PayloadFrom(field.Value); | ||
if (payload is ExceptionData exception) | ||
payload = ExceptionFromProto(exception); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Old code would fail if it encounters an |
||
serializationInfo.AddValue(field.Key, payload); | ||
} | ||
|
||
Exception obj = null; | ||
|
@@ -137,5 +149,8 @@ public Exception ExceptionFromProtoNet(Proto.Msg.ExceptionData proto) | |
|
||
return obj; | ||
} | ||
|
||
private string ValueOrNull(string value) | ||
=> string.IsNullOrEmpty(value) ? null : value; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Default value for strings inside an |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Old code would fail if it encounters an Exception property inside an Exception, have to make sure that the serializer recurse through these