1
我有一個相當簡單的開始WebAPI項目,但沒有太多。由於SQL ServerVersion錯誤,Web API無法序列化簡單對象
我有一個遺留數據庫,我正在查找一些數據(它的SQL Express 2012 R2)。然後我用某些屬性填充本地類並返回它。
但是當試圖序列化我的簡單的類與此錯誤的JSON序列化失敗:
Error getting value from 'ServerVersion' on 'System.Data.SqlClient.SqlConnection'.
這是我序列化類。該BaseEntity只上有一個屬性,它是數據庫方面
public class User : BaseEntity
{
public int Id;
public string Email;
public int Strikes;
public Guid AuthenticationKey;
public User()
{
}
這是控制器
public User PutAuthenticate(AuthenticationPayload payload)
{
if (!ModelState.IsValid)
{
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.BadRequest, ModelState));
}
User user;
try
{
user = new User(payload.Email, payload.Password);
if (user.Strikes >= 3)
{
HttpError error = new HttpError("Your account has been locked please contact us to unlock");
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.Unauthorized, error));
}
}
catch (CANotFoundException)
{
throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.Unauthorized));
}
return user;
}
UpVote,謝謝弟兄你解決了我的問題:) – Aria