RBS
asked on
WebAPI 2 - Adding related object generates JSON error when retrieving values
Hi:
I am using WebAPI 2.1. I have a simple class defined as follows:
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.InvalidOperationEx ception",
StackTrace: null,
InnerException: {
Message: "An error has occurred.",
ExceptionMessage: "Error getting value from 'Activity' on 'System.Data.Entity.Dynami cProxies.S tatement_6 2447580493 22F2013F45 504488584D 62A3E3D45B 5CDB4D16F0 EA721E9E73 7B1'.",
ExceptionType: "Newtonsoft.Json.JsonSeria lizationEx ception",. ........:
Any suggestions on what I am doing wrong greatly appreciated.
RBS
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; }
}
When I make an http request, such as mysite.com/api/statements,
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.InvalidOperationEx
StackTrace: null,
InnerException: {
Message: "An error has occurred.",
ExceptionMessage: "Error getting value from 'Activity' on 'System.Data.Entity.Dynami
ExceptionType: "Newtonsoft.Json.JsonSeria
Any suggestions on what I am doing wrong greatly appreciated.
RBS
How is Activity declared?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It was a long and complicated error message and thought trial and error was able to come up with solution