[英]Web Api Get method returns HTTP/1.1 500 Internal Server Error
I create controllers using entity. 我使用实体创建控制器。 There are severel models in my project and for every model in context "Get method" works fine, but this one, which is the same like others, did'nt.
我的项目中有严格的模型,对于上下文中的每个模型,“获取方法”都可以正常工作,但是与其他模型一样,它没有。
This is simple code: 这是简单的代码:
// GET: api/Proizvodi
public IQueryable<Proizvodi> GetProizvodi()
{
return db.Proizvodi;
}
I tested with fidler and this is message: 我测试了fidler,这是消息:
{"Message":"An error has occurred.","ExceptionMessage":"The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'.","ExceptionType":"System.InvalidOperationException","StackTrace":null,"InnerException":{"Message":"An error has occurred.","ExceptionMessage":"Self referencing loop detected with type 'System.Data.Entity.DynamicProxies.Proizvodi_B322A16527536C491FCFE47A9DC60617BBB3A2AAF1FABD41D99F924F0D8FE589'. Path '[0].JediniceMjere.Proizvodi'.","ExceptionType":"Newtonsoft.Json.JsonSerializationException",...
{“ Message”:“发生错误。”,“ ExceptionMessage”:“” ObjectContent`1“类型未能序列化内容类型'application / json; charset = utf-8'的响应主体。”,“ ExceptionType “:” System.InvalidOperationException“,” StackTrace“:null,” InnerException“:{” Message“:”发生错误。“,” ExceptionMessage“:”检测到类型为'System.Data.Entity.DynamicProxies的自引用循环..Proizvodi_B322A16527536C491FCFE47A9DC60617BBB3A2AAF1FABD41D99F924F0D8FE589'。路径'[0] .JediniceMjere.Proizvodi'。“,” ExceptionType“:” Newtonsoft.Json.JsonSerializationException“,...
I know there are severel same question and im looking for answer but can't find. 我知道有相同的问题,我正在寻找答案,但找不到。 Is there problem with entity freimwork, problem with serialization or something else .
实体框架是否存在问题, 序列化是否存在问题或其他问题 ? ??
??
Maybe this help: when i delete all records from database for this model/class, "Proizvodi", i get "HTTP/1.1 200 OK". 也许有帮助:当我从数据库中删除该模型/类“ Proizvodi”的所有记录时,我得到“ HTTP / 1.1 200 OK”。
Add thhe following to 将以下内容添加到
Global.asax
HttpConfiguration config = GlobalConfiguration.Configuration;
config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.