Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2014-03-29
3
2,078 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
ID: 39966652
How is Activity declared?
0
 

Accepted Solution

by:
RBS earned 0 total points
ID: 39967674
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
ID: 39979865
It was a long and complicated error message and thought trial and error was able to come up with solution
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

828 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