core
core copied to clipboard
Serialization of NaN value.
As for now following remote method gives WriteException on sending response.
[Remote]
public static Task<float> GetNaN()
{
return Task.FromResult(float.NaN);
}
[WriteException: Выдано исключение типа "WebSharper.Core.Json+WriteException".]
WebSharper.Core.Json.wN@284(TextWriter writer, String x) +105
WebSharper.Core.Json.Stringify(Value v) +57
[email protected](Value _arg1) +12
[email protected](a a) +63
Microsoft.FSharp.Control.AsyncIAsyncResult`1.GetResult() +356
Microsoft.FSharp.Control.AsBeginEndHelpers.endAction(IAsyncResult iar) +64
<StartupCode$FSharp-Core>[email protected](IAsyncResult iar) +40
WebSharper.Web.RpcHandler.System-Web-IHttpAsyncHandler-EndProcessRequest(IAsyncResult res) +13
System.Web.CallHandlerExecutionStep.InvokeEndHandler(IAsyncResult ar) +152
System.Web.CallHandlerExecutionStep.OnAsyncHandlerCompletion(IAsyncResult ar) +126
This exception has no message about the value that caused the exception. So in more complicated structures there is a challenge to find out what was the real problem:
[WriteException: Выдано исключение типа "WebSharper.Core.Json+WriteException".]
WebSharper.Core.Json.wN@284(TextWriter writer, String x) +105
WebSharper.Core.Json.wA@274(TextWriter writer, FSharpList`1 x) +77
WebSharper.Core.Json.wO@308(TextWriter writer, FSharpList`1 x) +50
WebSharper.Core.Json.wO@308(TextWriter writer, FSharpList`1 x) +115
WebSharper.Core.Json.wO@308(TextWriter writer, FSharpList`1 x) +50
WebSharper.Core.Json.wO@308(TextWriter writer, FSharpList`1 x) +115
WebSharper.Core.Json.wA@274(TextWriter writer, FSharpList`1 x) +77
WebSharper.Core.Json.wO@308(TextWriter writer, FSharpList`1 x) +50
WebSharper.Core.Json.wO@308(TextWriter writer, FSharpList`1 x) +115
WebSharper.Core.Json.wA@274(TextWriter writer, FSharpList`1 x) +41
WebSharper.Core.Json.wO@308(TextWriter writer, FSharpList`1 x) +50
WebSharper.Core.Json.wO@308(TextWriter writer, FSharpList`1 x) +115
WebSharper.Core.Json.wO@308(TextWriter writer, FSharpList`1 x) +115
WebSharper.Core.Json.Stringify(Value v) +57
How this problem will be resolved? Will NaN be serialized in future?
Thanks for the report!
Currently RPC results are parsed with a JSON.parse on the client and then have object prototypes restored which are also returned by the RPC. A simple way to include some special values would be (like NaN and Infinity) is to encode them as special objects (for example returning { "$Val": "NaN" }) that a reviver function added to JSON.parse can restore to the values.
Similarly the JSON.stringify used to send RPC argument values need a replacer, transforming these values in the other direction.