C# 当两个Json对象包含相同的base64编码字符串时,ASP.NET JsonResult会导致500服务器错误

C# 当两个Json对象包含相同的base64编码字符串时,ASP.NET JsonResult会导致500服务器错误,c#,asp.net,json,ajax,C#,Asp.net,Json,Ajax,我将向客户端返回一个序列化的模型列表。在这些模型中,有一个名为“DocumentBody”的属性,它是文件(通常是图像)的编码字符串 在我将一个重复文件上传到GetAnnotationsForEntity()中获取的数据之前,一切都按预期运行。一旦我尝试返回包含两个具有相同“DocumentBody”的对象的Json,我的Chrome控制台中就会出现一个500服务器错误,没有其他信息。我已经完成了控制器操作,没有抛出异常 我不了解Json的哪些方面会使它在这个实例中失败?一旦从列表中删除具有重复

我将向客户端返回一个序列化的模型列表。在这些模型中,有一个名为“DocumentBody”的属性,它是文件(通常是图像)的编码字符串

在我将一个重复文件上传到GetAnnotationsForEntity()中获取的数据之前,一切都按预期运行。一旦我尝试返回包含两个具有相同“DocumentBody”的对象的Json,我的Chrome控制台中就会出现一个500服务器错误,没有其他信息。我已经完成了控制器操作,没有抛出异常

我不了解Json的哪些方面会使它在这个实例中失败?一旦从列表中删除具有重复“DocumentBody”的对象,所有功能都将再次成功运行。我在其他所有字段中尝试了不同的值,没有任何不良影响。我还在Json查看器中查看了Json字符串,其结构似乎也符合要求

以下是相关代码:

职位:

控制器操作:

public ActionResult GetAnnotationsForEntity(EntityType entityType, string entityId)
        {
            List<AnnotationModel> annotationsForEntity = new List<AnnotationModel>();
            if (!string.IsNullOrWhiteSpace(entityId))
            {
                DynamicsHelper.GetAnnotationsForEntity(entityType, new Guid(entityId))?.ToList()?.ForEach(a =>
                {
                    annotationsForEntity.Add(new AnnotationModel(a.Id, GetOffsetDateTimeForTimeZone(a.ModifiedOn), a.FileName, a.Subject, a.DocumentBody, a.NoteText, GetCulture()));
                });
            }
            string serializedAnnotations = Newtonsoft.Json.JsonConvert.SerializeObject(annotationsForEntity);
            return Json(serializedAnnotations);
        }

如有任何见解,将不胜感激。同时,我通过根本不返回带有“DocumentBody”的模型和Json对象来解决这个问题,但如果不知道它为什么会失败,我就不喜欢这个解决方案。

在chrome开发工具-网络选项卡中检查请求的响应,它应该有错误消息。或者检查visual studioregarding模型中的输出选项卡-我不认为
CultureInfo
可序列化为jsonError 500只是“在处理请求期间,服务器上存在未处理的异常”。它本身不是很有用。调试菜单>>异常窗口>>勾选“CLR异常”的“抛出时中断”,然后向调试服务器发出导致错误的请求。VS现在应该在抛出错误后立即停止,以便您可以看到它是什么。请注意,对于某些上下文/场景,visual studio可能不会因异常而中断,除非该请求源自您开始调试时出现的浏览器。。dev tools中请求的响应仅给出通用的HTML“HTTP错误500.0-内部服务器错误”页面,讨论NTFS权限和其他内容。VS中的输出(来自调试)没有任何用处。
public ActionResult GetAnnotationsForEntity(EntityType entityType, string entityId)
        {
            List<AnnotationModel> annotationsForEntity = new List<AnnotationModel>();
            if (!string.IsNullOrWhiteSpace(entityId))
            {
                DynamicsHelper.GetAnnotationsForEntity(entityType, new Guid(entityId))?.ToList()?.ForEach(a =>
                {
                    annotationsForEntity.Add(new AnnotationModel(a.Id, GetOffsetDateTimeForTimeZone(a.ModifiedOn), a.FileName, a.Subject, a.DocumentBody, a.NoteText, GetCulture()));
                });
            }
            string serializedAnnotations = Newtonsoft.Json.JsonConvert.SerializeObject(annotationsForEntity);
            return Json(serializedAnnotations);
        }
public class AnnotationModel
    {
        private readonly CultureInfo _cultureInfo;
        private readonly DateTime? _modifiedOn;

        public Guid Id { get; set; }
        public string ModifiedOn => _modifiedOn.HasValue ? _modifiedOn.Value.ToString(_cultureInfo) : "";
        public string FileName { get; set; }
        public string Subject { get; set; }
        public string DocumentBody { get; set; }
        public string NoteText { get; set; }

        public AnnotationModel(Guid id, DateTime? modifiedOn, string fileName, string subject, string documentBody, string noteText, CultureInfo cultureInfo)
        {
            Id = id;
            _modifiedOn = modifiedOn;
            FileName = fileName;
            Subject = subject;
            DocumentBody = documentBody;
            NoteText = noteText;
            _cultureInfo = cultureInfo;
        }
    }