Closed graforlock closed 6 years ago
Did you figure out what the problem was?
Ah yes, it was not Giraffe per se but how F# plays with SignalR. Stack traces seems very vague and doesn't explain why is it happening, but adding type annotations here:
member x.SendMessage (user: string, msg: string) =
task {
do! x.Clients.All.SendAsync("ReceiveMessage", user, msg)
}
Fixes the issue.
I am encountering this same issue. No solution for it yet on my end and this is with C#.
I found the root issue in my case. You cannot seem to have generic public methods on SignalR hubs. SignalR will attempt to do some internal registration for public methods it seems and this will fail when they are generic.
In my case, the solution was to just make my interface method implementation explicit. If you have generic method members just make them private or something. That should work too.
Better warnings/errors should be thrown when this occurs in my opinion!
Obviously this isn't an issue with Giraffe. But with ASP Core SignalR itself. However, seemed relevant to post here since this is where Google brings you.
I'll open an issue on the ASP Core github about this too.
Just a note here (because FSharp-Giraffe-SignalR combination is not well documented)... You can also to strongly typed hub:
type IMessageToClient =
abstract NotifyDeal : string -> Task
type SignalHub() as this =
inherit Hub<IMessageToClient>()
member __.BuyStocks (company:string) (amount:int) =
//...
this.Clients.All.NotifyDeal "New deal was done!"
Sadly I have not found support to EnableJavaScriptProxies
or how to generate proxies manually with a tool like signalr.exe
was.
I am basically trying to replicate this tutorial https://docs.microsoft.com/en-us/aspnet/core/tutorials/signalr?view=aspnetcore-2.1&tabs=visual-studio-code.
In
Program.fs
I have:And in
Services/ChatHub.fs
:Upon the attempt of running the app, the exception I am getting is:
Do you know what is the possible cause for this?