Websharper 无法反序列化联合类型
我有以下客户端代码:
|>! OnClick (fun _ _ -> Server.CreateBug input.Value |> Server.SendCommand)
这是类型和服务器代码:
type Command =
| CreateBug of string
| Query of Query * AsyncReplyChannel<string>
[<Rpc>]
let SendCommand cmd =
dispatcher.Post cmd
客户端可以将其序列化为: [{"$":0,"$0":"test"}]
但在调试时出现以下日志错误:
WebSharper.Web 错误:0:无法执行远程调用。无法获取 JSON 反序列化器:ClientReferral.Server+Command[]
WebSharper 错误:0:无法执行远程调用。无法获取 JSON 反序列化器:ClientReferral.Server+Command[]
此代码相当简单,并且似乎没有任何内容表明它在 WebSharper 手册中不起作用。我什至记得这样使用过,所以我不知道出了什么问题。
编辑: 这是查询的定义:
type Query =
| GetBugs
| GetBugInfo of int
I have the following client code:
|>! OnClick (fun _ _ -> Server.CreateBug input.Value |> Server.SendCommand)
Here's the type and server code:
type Command =
| CreateBug of string
| Query of Query * AsyncReplyChannel<string>
[<Rpc>]
let SendCommand cmd =
dispatcher.Post cmd
The client can serialize this to: [{"$":0,"$0":"test"}]
But then I get the following log error when debugging:
WebSharper.Web Error: 0 : Failed to execute a remote call. Failed to get JSON deserializer for: ClientReferral.Server+Command[]
WebSharper Error: 0 : Failed to execute a remote call. Failed to get JSON deserializer for: ClientReferral.Server+Command[]
This code is rather trivial and there doesn't seem to be anything indicating it wouldn't work in the WebSharper manual. I even remember using it like that, so I don't know what's wrong.
Edit:
This is the definition of Query:
type Query =
| GetBugs
| GetBugInfo of int
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实上,错误发生在运行时而不是编译时,这绝对是一个错误,我将在周一尝试重现和修复。
从技术上讲,由于 AsyncReplyChannel<'T>没有默认构造函数 WebSharper 无法为其构造反序列化器。
往上看,我无法理解你的意图。为什么通过 RPC 发送函数同构类型?
此外,这:
在我看来,这就像尝试在服务器上构造一个对象,然后无偿地将其发送到客户端并返回,然后用它做一些事情 - 这是正确的吗?我假设 Server.* 函数在服务器上执行。如果是这样,则必须将其重构为单个调用:
the fact that the error is happening at runtime and not at compile time is definitely a bug, I will try to reproduce and fix on Monday.
Technically, since AsyncReplyChannel<'T> does not have a default constructor WebSharper cannot construct a deserializer for it.
Looking at the higher level, I cannot understand your intent. Why send a function-isomorphic type over RPC?
Moreover, this:
This looks to me like an attempt to construct an object on the server, then gratuitously send it to the client and back, and then do something with it - is this right? I assume Server.* functions execute on the server. If so, it must be refactored to a single call: