Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7781321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T19:11:26+00:00 2026-06-01T19:11:26+00:00

I had originally asked this question: How Do I Resolve "A specified Include path

  • 0

I had originally asked this question:
How Do I Resolve "A specified Include path is not valid"? which was answered, and my .Include() is now working, however, when the serializer tries to work it’s magic, I get the following error:

You must write an attribute 'type'='object' after writing the attribute 
with local name '__type'.

Here’s what I’m doing to return the data:

var everything = dc.Categories
            .Include(c => c.Products);

My class definitions are fairly straightforward:

public class Category
{
    public int CategoryId { get; set; }
    public string Title { get; set; }

    public virtual ICollection<Product> Products { get; set; }
}

public class Product
{
    public int ProductId { get; set; }
    public string Title { get; set; }

    public virtual Category Category { get; set; }
}

public class ProductDataContext : DbContext
{
    public DbSet<Category> Categories { get; set; }
    public DbSet<Product> Products { get; set; }
}

I also tried removing ‘virtual’ but then I get circular references. I tried making the setter on ICollection Products private (as suggested here: http://forums.asp.net/t/1773164.aspx/1), which gets the error to clear, but then my products aren’t part of the returned JSON.

What do I need to do to get the data to serialize with the categories and their products within?

EDIT
Here was the stack trace I was getting:

[SerializationException: Object graph for type &#39;System.Collections.Generic.List`1[[Test.Models.Product, Test.Models, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]&#39; contains cycles and cannot be serialized if reference tracking is disabled.]
System.Web.Http.WebHost.HttpControllerHandler.EndProcessRequest(IAsyncResult result) +30206
System.Web.Http.WebHost.HttpControllerHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +10
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +9478661
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean&amp; completedSynchronously) +178
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T19:11:27+00:00Added an answer on June 1, 2026 at 7:11 pm

    In order to fix this I needed to:

    1. Disable lazy loading, and
    2. Use the IgnoreDataMember from System.Runtime.Serialization as an attribute on the Category navigation property (the back-reference on the Product class).

    Hope this helps someone.

    To get around the XML-ish errors I used help from here:
    http://www.strathweb.com/2012/03/serializing-entity-framework-objects-to-json-in-asp-net-web-api/

    To get around the problem with the cyclic references, I used this as a guide:
    MVC 4, Upshot entities cyclic references

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This question originally asked which is the best method for uploading files via SFTP
A co-worker asked about some code like this that originally had templates in it.
I asked this question before but with less information than I have now. What
This question originally asked (wrongly) what does | mean in Python, when the actual
This is a followup to a question I asked yesterday: Have you ever had
I originally asked this question on ServerFault and haven't got any response and I
I originally asked this question: Regular Expression in gVim to Remove Duplicate Domains from
Had this working; at one stage. The problem is the following text is now
This has been asked before, but the other poster's concern had more to do
This relates to another question I asked earlier today. I built SVN 1.6.2 from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.