0

I have a few server-side objects with inheritrence hierarchy, like this:

[<JavaScriptExport>]
type [<AbstractClass>] A() = ...

[<JavaScriptExport>]
type [<AbstractClass>] B() =
    inherit A()

[<JavaScriptExport>]
type C() =
    inherit B()

The above objects have certain fields and methods, which I have omitted for brevity. All of those can be compiled to javascript -- I receive no build errors.

I have an RPC that would return a server-side created instance of such an object:

module Remoting =
    [<Rpc>]
    let GetObject (arg: string) : Async<A> =
        async {
            return (upcast C() : A)
        }

When I invoke the rpc and debug the relevant javascript in my browser, I see that the retured object is {}. I do not see any server-side errors in the logs.

If I change the signature of the Rpc to be of the concrete type GetObject (arg: string) : Async<C>, I receive an error on the server:

System.Exception: Could not load method (GetObject : System.String -> Microsoft.FSharp.Control.FSharpAsync`1<C>) candidates: [|"(GetObject : System.String -> Microsoft.FSharp.Control.FSharpAsync`1<.C>)"|]

It seems that it looks for a type .C instead of type C (emphasys on the leading dot)

What is the reason for this behavior? Is there a way to get my object instance from the server without having to specify its concrete type?


Update

Interestingly, it works if I replace the RPC call with a client-side method like this:

[<JavaScript>]
let GetObjectClient (arg : string) : A =
    (upcast C() : A)

I suppose there are issues converting the server-side object to its corresponding client counterpart. Still I have no idea how to get over this

Ivaylo Slavov
  • 8,839
  • 12
  • 65
  • 108
  • 1
    The limitation in RPC calls is about what can be serialized through json. Objects with inheritance may be too complex to communicate with RPC. Think more about communicating information and less about complex structures with methods or functions, – AMieres Jan 05 '19 at 23:14
  • @AMieres, alas, it is as you say. I was hoping that objects with default constructor would get recognized and re-instantiated on the client but to no avail. I have asked [another question](https://stackoverflow.com/q/54109947/795158) which I believe better describes my case. I plan to delete this one in a day – Ivaylo Slavov Jan 09 '19 at 12:32

0 Answers0