Solved

WebAPI 2 - Adding related object generates JSON error when retrieving values

Posted on 2014-03-29
3
2,023 Views
Last Modified: 2014-04-05
Hi:

I am using WebAPI 2.1.  I have a simple class defined as follows:

 public class Statement
    {
        public Statement(int id, string name)
        {
            Id = id;
            Name= name;
        }

        //For EF
        public Statement()
        {

        }
        public int Id { get; set; }
        public string Name { get; set; }
    }
      

Open in new window


When I make an http request, such as mysite.com/api/statements, it works fine and retrieves the data.  When I add the the following property to my class -
        public virtual Activity Activity { get; set; } - and make a get request, I get the following error message

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: "Error getting value from 'Activity' on 'System.Data.Entity.DynamicProxies.Statement_6244758049322F2013F45504488584D62A3E3D45B5CDB4D16F0EA721E9E737B1'.",
ExceptionType: "Newtonsoft.Json.JsonSerializationException",.........:

Any suggestions on what I am doing wrong greatly appreciated.

RBS
0
Comment
Question by:RBS
  • 2
3 Comments
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
How is Activity declared?
0
 

Accepted Solution

by:
RBS earned 0 total points
Comment Utility
Hi:

Sorry - I just figured out what the problem was - It looks like I needed to declare a MultipleActiveResultSets = true in my web.config

RBS
0
 

Author Closing Comment

by:RBS
Comment Utility
It was a long and complicated error message and thought trial and error was able to come up with solution
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

5 Experts available now in Live!

Get 1:1 Help Now