Solved

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

Posted on 2014-03-29
3
2,145 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
[X]
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
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

622 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