Websharper 无法反序列化联合类型

发布于 2024-11-27 11:45:14 字数 753 浏览 0 评论 0原文

我有以下客户端代码:

|>! 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怪我鬧 2024-12-04 11:45:14

事实上,错误发生在运行时而不是编译时,这绝对是一个错误,我将在周一尝试重现和修复。

从技术上讲,由于 AsyncReplyChannel<'T>没有默认构造函数 WebSharper 无法为其构造反序列化器。

往上看,我无法理解你的意图。为什么通过 RPC 发送函数同构类型?

此外,这:

|>! OnClick (fun _ _ -> Server.CreateBug input.Value |> Server.SendCommand)

在我看来,这就像尝试在服务器上构造一个对象,然后无偿地将其发送到客户端并返回,然后用它做一些事情 - 这是正确的吗?我假设 Server.* 函数在服务器上执行。如果是这样,则必须将其重构为单个调用:

|>! OnClick (fun _ _ -> Server.SendBugCommand input.Value)

[<Rpc>]
let SendBugCommand x =
    CreateBug x
    |> SendCommand

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:

|>! OnClick (fun _ _ -> Server.CreateBug input.Value |> Server.SendCommand)

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:

|>! OnClick (fun _ _ -> Server.SendBugCommand input.Value)

[<Rpc>]
let SendBugCommand x =
    CreateBug x
    |> SendCommand
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文