Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SignalR error Error: Failed to invoke 'Methodname' due to an error on the server

i am getting this error Error: Failed to invoke 'MoveLobbyCard' due to an error on the server. when trying to perform an action in lobby my js code:

"use strict";

var connection = new signalR.HubConnectionBuilder().withUrl("/hub").build();

connection.start().then(function () {
}).catch(function (err) {
    return console.error(err.toString());
});

connection.on("UserConnected", function (ConnectionId) {
    $("#userlist").append($("<li>").text(ConnectionId + "has joined"));
    var lobbyID = $('#lobbyID').text();
    connection.invoke("JoinLobby", lobbyID).catch(function (err) {
        return console.error(err.toString());
    });
});

connection.on("CardMoved", function (id) {
    $('#'+id).addClass("moved");
});


$('.card').on("click", function (){
    var id = $(this).attr("id");
    connection.invoke("MoveLobbyCard",id,lobbyID).catch(function (err) {
        return console.error(err.toString());
    });
});

it does add to groups but i have no idea whats causing the error

like image 450
Turqay Umudzade Avatar asked Oct 16 '25 10:10

Turqay Umudzade


1 Answers

For me the error was caused by a method signature on the hub expecting an integer but javascript providing it (a number) as a string. I changed the hub to accept a string and parsed it to an integer before use and it was all good.

like image 109
Mike Furmedge Avatar answered Oct 18 '25 00:10

Mike Furmedge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!