Closed pardahlman closed 8 years ago
it's very hardly to implements InnerException, StackTrace, Message etc. (de)serializable for json or xml.
I reveiwed the .NetCore Framework XmlSerializer it can serialize/deserialize InnerException, the method is use Reflection to access private fields. It's a very low level usage, private field is not contract and variable.
corefx\src\System.Private.DataContractSerialization\src\System\Runtime\Serialization\ExceptionDataContract.cs
private static Dictionary<string, string> CreateExceptionFields()
{
var essentialExceptionFields = new Dictionary<string, string>(12);
essentialExceptionFields.Add("_className", "ClassName");
essentialExceptionFields.Add("_message", "Message");
essentialExceptionFields.Add("_data", "Data");
essentialExceptionFields.Add("_innerException", "InnerException");
essentialExceptionFields.Add("_helpURL", "HelpURL");
essentialExceptionFields.Add("_stackTraceString", "StackTraceString");
essentialExceptionFields.Add("_remoteStackTraceString", "RemoteStackTraceString");
essentialExceptionFields.Add("_remoteStackIndex", "RemoteStackIndex");
essentialExceptionFields.Add("_exceptionMethodString", "ExceptionMethod");
essentialExceptionFields.Add("_HResult", "HResult");
essentialExceptionFields.Add("_source", "Source");
essentialExceptionFields.Add("_watsonBuckets", "WatsonBuckets");
return essentialExceptionFields;
}
since Framework need to do like this why not support ISerializable?
Hi @chrishaly, thanks for the input! I did a somewhat similar discovery myself when looking into this. The ambition for 1.10.0
is to support netstandard1.5
, and that is somewhat limiting to what can be done. Until there is a clean way to serialize exception for .NET Core, we'll have to do with the work-around in 3afb94d. Exception will be captured, metadata extracted and re-thrown in the Requester.
Let me know if you have any other suggestions for how to achieve this!
Serialization in general, and of or Exception in particular is still an unresolved topic for .NET Core (https://github.com/dotnet/coreclr/issues/2715, https://github.com/dotnet/corefx/issues/6564). Until this issue is resolved, we should overlook how
MessageHandlerException
should be serialized and re-thrown for RPC.