SignalR 与外部模型挂起 class

SignalR hang with external model class

我有一个非常简单的 SignalR 集线器,每当我尝试将我的模型 classes 移动到 class 库时,我注意到集线器上挂起。每当我将模型 classes 留在 ASP.net 项目中时,它工作正常并从服务器检索对象但是一旦我将模型 class 移动到 class 库(对于跨项目重用)来自客户端(js 端)的 SignalR 调用挂起。我可以看到请求通过设置断点到达集线器,但之后它不会在客户端 return .. 这里有什么线索吗?

我在客户端启用了日志记录:

[16:37:39 GMT+0200 (W. Europe Daylight Time)] SignalR: Client subscribed to hub 'myHubhub'.
jquery.signalR.min-2.2.0.js:8 [16:37:39 GMT+0200 (W. Europe Daylight Time)] SignalR: Negotiating with '/signalr/negotiate?clientProtocol=1.5&connectionData=%5B%7B%22name%22%3A%22myHubhub%22%7D%5D'.
jquery.signalR.min-2.2.0.js:8 [16:37:39 GMT+0200 (W. Europe Daylight Time)] SignalR: serverSentEvents transport starting.
jquery.signalR.min-2.2.0.js:8 [16:37:39 GMT+0200 (W. Europe Daylight Time)] SignalR: Attempting to connect to SSE endpoint 'http://localhost:1275/signalr/connect?transport=serverSentEvents&clientProt…VWFxHpWoC0T&connectionData=%5B%7B%22name%22%3A%22myHubhub%22%7D%5D&tid=6'.
jquery.signalR.min-2.2.0.js:8 [16:37:39 GMT+0200 (W. Europe Daylight Time)] SignalR: EventSource connected.
jquery.signalR.min-2.2.0.js:8 [16:37:39 GMT+0200 (W. Europe Daylight Time)] SignalR: serverSentEvents transport connected. Initiating start request.
jquery.signalR.min-2.2.0.js:8 [16:37:39 GMT+0200 (W. Europe Daylight Time)] SignalR: The start request succeeded. Transitioning to the connected state.
jquery.signalR.min-2.2.0.js:8 [16:37:39 GMT+0200 (W. Europe Daylight Time)] SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332, keep alive timeout of 20000 and disconnecting timeout of 30000
jquery.signalR.min-2.2.0.js:8 [16:37:39 GMT+0200 (W. Europe Daylight Time)] SignalR: Invoking myHubhub.RetrieveMyObjects

服务器端集线器方法:

public IEnumerable<MyModel> RetrieveMyObjects()
{
    using (DatabaseContext dbContext = new DatabaseContext())
    {
        Debug.WriteLine("RetrieveMyObjects()");
        List<MyModel> objs = dbContext.MyObjects.ToList();
        return objs;
    }
}

客户端调用:

@section scripts
{        
    <script>       
        $(function () {           
            // Reference the auto-generated proxy for the hub.
            var chat = $.connection.myHub;
            // Create a function that the hub can call back to display messages.
            chat.client.addNewMessageToPage = function (name, message) {
                // Add the message to the page.
                $('#discussion').append('<li><strong>' + htmlEncode(name)
                    + '</strong>: ' + htmlEncode(message) + '</li>');
            };
            $.connection.hub.logging = true;
            // Start the connection.
            $.connection.hub.start().done(function () {

                // Call the Send method on the hub.
                chat.server.retrieveMyObjects().done(function (result) {
                    console.log("yep");
                    //Process logic
                }).fail(function (err) {
                    console.log('Could not Connect! ' + err);
                });
            });
        });

    </script>
}

嗯,我开始拆解我的模型并找到了答案。我有一个标有“[JsonConverter(typeof(StringEnumConverter))]”的枚举 属性,用于将枚举序列化为字符串值。每当模型在外部 class 库中时,这显然会破坏一些东西?

编辑: 问题:外部 class lib 引用了 Netwonsoft.Json 7.0.0 而我的 ASP.NET 项目引用了版本 6.0.4.. 一旦我在 [=19] 上将 Netwonsoft.Json 降级到 6.0.4 =] lib 一切都按预期工作。