Failed to load resource: the server responded with a status of 500 (Internal Server Error)

【前言】

  今天在做番茄时钟(dmtodo)的时候,出现了这个问题。

Failed to load resource: the server responded with a status of 500 (Internal Server Error)


Failed to load resource: the server responded with a status of 500 (Internal Server Error)

不过看不到详细的报错信息。那就逐步调试一下,就会出现详细的错误:

POST http://localhost:29230/Register/Register 500 (Internal Server Error),点开这个,就会出现详细错误


Failed to load resource: the server responded with a status of 500 (Internal Server Error)

详细的错误信息就出来了:System.InvalidOperationException: 序列化类型为“System.Data.Entity.DynamicProxies.t_user_4C42A0667A684993DA6693ACCBED26AC0D2636CF73CCF638833CF2CB0FF7AF0C”的对象时检测到循环引用。


【原因】

因为这个表和另一个表是有一对多关系的,当序列化表1的时候,会找到和另一个表2关联的字段,就会到另一个表2中序列化,然后另一个表2中也有一个字段和表1相关联.这样.序列化就会发生这种错误!

【解决办法】

在进行增删改查数据库的上面加上这句话:db.Configuration.ProxyCreationEnabled = false;

办法不止有一种,推荐一篇博客链接:点击打开链接


【总结】


通过解决这个问题,知道以后如何利用互联网查找问题,解决问题。还是很有收获的。