Serializing Complex ViewModel with Json.Net Destabilization Error on Latest Version

Posted by dreadlocks1221 on Stack Overflow See other posts from Stack Overflow or by dreadlocks1221
Published on 2012-09-17T15:20:53Z Indexed on 2012/09/17 15:37 UTC
Read the original article Hit count: 494

Filed under:
|
|
|

I just added the latest Version of JSON.Net and I get the System.Security.VerificationException: Operation could destabilize the runtime error when trying to use a controller (while running the application). I read in other posts that this issue should have been fixed in release 6 but I still have the problem. I even added *Newtonsoft.* to the ignore modules in the intellitrace options, which seems to have suppressed the error, but the post will just run forever and not return anything.

Any help I can get would be greatly appreciated.

    [HttpPost]
    public string GetComments(int ShowID, int Page)
    {
        int PageSize = 10;

        UserRepository UserRepo = new UserRepository();
        ShowCommentViewModel viewModel = new ShowCommentViewModel();
        IQueryable<Comment> CommentQuery = showRepository.GetShowComments(ShowID);
        var paginatedComments = new PaginatedList<Comment>(CommentQuery, Page, PageSize);
        viewModel.Comments = new List<CommentViewModel>();
        foreach (Comment comment in CommentQuery.Take(10).ToList())
        {
            CommentViewModel CommentModel = new CommentViewModel
            {
                Comment = comment,
                PostedBy = UserRepo.GetUserProfile(comment.UserID)
            };

            IQueryable<Comment> ReplyQuery =     showRepository.GetShowCommentReplies(comment.CommentID);
            int ReplyPage = 0;
            var paginatedReplies = new PaginatedList<Comment>(ReplyQuery, ReplyPage, 3);
            CommentModel.Replies = new List<ReplyModel>();

            foreach (Comment reply in ReplyQuery.Take(3).ToList())
            {
                ReplyModel rModel = new ReplyModel
                {
                    Reply = reply,
                    PostedBy = UserRepo.GetUserProfile(reply.UserID)
                };

                CommentModel.Replies.Add(rModel);
            }

            CommentModel.RepliesNextPage = paginatedReplies.HasNextPage;
            CommentModel.RepliesPeviousPage = paginatedReplies.HasPreviousPage;
            CommentModel.RepliesTotalPages = paginatedReplies.TotalPages;
            CommentModel.RepliesPageIndex = paginatedReplies.PageIndex;
            CommentModel.RepliesTotalCount = paginatedReplies.TotalCount;
            viewModel.Comments.Add(CommentModel);

        }


        viewModel.CommentsNextPage = paginatedComments.HasNextPage;
        viewModel.CommentsPeviousPage = paginatedComments.HasPreviousPage;
        viewModel.CommentsTotalPages = paginatedComments.TotalPages;
        viewModel.CommentsPageIndex = paginatedComments.PageIndex;
        viewModel.CommentsTotalCount = paginatedComments.TotalCount;

        return JsonConvert.SerializeObject(viewModel, Formatting.Indented);
     }

© Stack Overflow or respective owner

Related posts about c#

Related posts about ASP.NET