Skip to content

Commit 93acab0

Browse files
committed
fixed exception serialization on dotnet core
1 parent 65bb0ab commit 93acab0

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

src/Elasticsearch.Net/Serialization/ElasticsearchNetJsonStrategy.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,11 @@ private IEnumerable<JsonObject> FlattenExceptions(Exception e)
4949
private JsonObject ToExceptionJsonObject(Exception e, int depth)
5050
{
5151
var o = new JsonObject();
52-
52+
#if !DOTNETCORE
5353
var si = new SerializationInfo(e.GetType(), new FormatterConverter());
5454
var sc = new StreamingContext();
5555
e.GetObjectData(si, sc);
56+
//TODO Loop over ISerializable data
5657

5758
var helpUrl = si.GetString("HelpURL");
5859
var stackTrace = si.GetString("StackTraceString");
@@ -62,8 +63,16 @@ private JsonObject ToExceptionJsonObject(Exception e, int depth)
6263
var hresult = si.GetInt32("HResult");
6364
var source = si.GetString("Source");
6465
var className = si.GetString("ClassName");
65-
66-
//TODO Loop over ISerializable data
66+
#else
67+
var helpUrl = e.HelpLink;
68+
var stackTrace = e.StackTrace;
69+
var remoteStackTrace = string.Empty;
70+
var remoteStackIndex = string.Empty;
71+
var exceptionMethod = string.Empty;
72+
var hresult = e.HResult;
73+
var source = e.Source;
74+
var className = string.Empty;
75+
#endif
6776

6877
o.Add("Depth", depth);
6978
o.Add("ClassName", className);
@@ -74,7 +83,9 @@ private JsonObject ToExceptionJsonObject(Exception e, int depth)
7483
o.Add("RemoteStackIndex", remoteStackIndex);
7584
o.Add("HResult", hresult);
7685
o.Add("HelpURL", helpUrl);
86+
#if !DOTNETCORE
7787
this.WriteStructuredExceptionMethod(o, exceptionMethod);
88+
#endif
7889
return o;
7990
}
8091

src/Tests/Reproduce/GithubIssue2052.cs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ public class GithubIssue2052
1818
private static object _bulkHeader =
1919
new { index = new { _index = "myIndex", _type = "myDocumentType" } };
2020
private readonly ElasticLowLevelClient _client;
21+
#if !DOTNETCORE
2122
private AssemblyName _assemblyName = new AssemblyName(typeof(GithubIssue2052).Assembly.FullName);
23+
#else
24+
private AssemblyName _assemblyName = new AssemblyName(typeof(GithubIssue2052).GetTypeInfo().Assembly.FullName);
25+
#endif
2226

2327
public GithubIssue2052()
2428
{
@@ -73,7 +77,7 @@ private IEnumerable<object> ExceptionJson(Exception e)
7377
int maxExceptions = 20;
7478
do
7579
{
76-
80+
#if !DOTNETCORE
7781
var si = new SerializationInfo(e.GetType(), new FormatterConverter());
7882
var sc = new StreamingContext();
7983
e.GetObjectData(si, sc);
@@ -86,6 +90,16 @@ private IEnumerable<object> ExceptionJson(Exception e)
8690
var hresult = si.GetInt32("HResult");
8791
var source = si.GetString("Source");
8892
var className = si.GetString("ClassName");
93+
#else
94+
var helpUrl = e.HelpLink;
95+
var stackTrace = e.StackTrace;
96+
var remoteStackTrace = string.Empty;
97+
var remoteStackIndex = string.Empty;
98+
var exceptionMethod = string.Empty;
99+
var hresult = e.HResult;
100+
var source = e.Source;
101+
var className = string.Empty;
102+
#endif
89103

90104
yield return new
91105
{
@@ -98,7 +112,9 @@ private IEnumerable<object> ExceptionJson(Exception e)
98112
RemoteStackIndex = remoteStackIndex,
99113
HResult = hresult,
100114
HelpURL = helpUrl,
115+
#if !DOTNETCORE
101116
ExceptionMethod = this.WriteStructuredExceptionMethod(exceptionMethod)
117+
#endif
102118
};
103119
depth++;
104120
e = e.InnerException;

0 commit comments

Comments
 (0)