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