我得到了一个' Newtonsoft.Json.JsonSerializationException'将以下Model类的实例传递给SignalR 2客户端时:
namespace MyApp.Models
{
using System;
using System.Collections.Generic;
public partial class SensorCheckpoint
{
public int SensorCheckpointID { get; set; }
public int SensorStatus { get; set; }
public int LineMount { get; set; }
public virtual Line Line { get; set; }
}
}

但是,如果我改为传递更简单的对象版本,则不会引发异常:
namespace MyApp
{
public class SensorCheckpointPush
{
public SensorCheckpointPush(SensorCheckpoint s) {
this.SensorNumber = s.SensorCheckpointID;
this.SensorStatus = s.SensorStatus;
this.LineMount = s.LineMount;
}
public int SensorNumber { get; set; }
public int SensorStatus { get; set; }
public int LineMount { get; set; }
}
}

甚至可以将Model对象传递给客户端吗?如果是这样,它是如何完成的? (我正在关注StockTicker示例,其中只传递简单对象)。将数据库对象发送到SignalR客户端的模式是什么? 我花了好几个小时试图找到答案。
Stack Trace是:
A first chance exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Newtonsoft.Json.dll
A first chance exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Newtonsoft.Json.dll
A first chance exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Newtonsoft.Json.dll
A first chance exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Newtonsoft.Json.dll
A first chance exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Newtonsoft.Json.dll
A first chance exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Newtonsoft.Json.dll
A first chance exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Newtonsoft.Json.dll
A first chance exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in mscorlib.dll
A first chance exception of type 'System.Net.WebSockets.WebSocketException' occurred in System.Web.dll
A first chance exception of type 'System.Net.WebSockets.WebSocketException' occurred in mscorlib.dll
A first chance exception of type 'System.OperationCanceledException' occurred in mscorlib.dll
A first chance exception of type 'System.OperationCanceledException' occurred in System.Web.dll
A first chance exception of type 'System.OperationCanceledException' occurred in mscorlib.dll
A first chance exception of type 'System.OperationCanceledException' occurred in mscorlib.dll
A first chance exception of type 'Newtonsoft.Json.JsonSerializationException' occurred in Microsoft.AspNet.SignalR.Core.dll
A first chance exception of type 'System.OperationCanceledException' occurred in mscorlib.dll