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 8209595
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:46:42+00:00 2026-06-07T09:46:42+00:00

How can I serialize an Entity Framework Code First Proxy when the class it

  • 0

How can I serialize an Entity Framework Code First Proxy when the class it is proxying is decorated with DataContractAttribute(IsReference = true)?

When using DataContractSerializer with ProxyContractResolver, I get the following:

The IsReference setting for type ‘System.Data.Entity.DynamicProxies.MyType_59A83378572C10D0B31B6892FB6C3E7428C4BA214322C7A77BD5E1EB19E529CA’ is ‘False’, but the same setting for its parent class ‘My.Namespace.MyType’ is ‘True’. Derived types must have the same value for IsReference as the base type. Change the setting on type

It seems that the EF Proxy Generator is not respecting the IsReference attribute, which I do need on the POCO (otherwise I end up with a stack overflow due to mutual referencing).

Is there any mechanism at all to serialize an EF Proxy under these circumstances? How?

  • 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-07T09:46:45+00:00Added an answer on June 7, 2026 at 9:46 am

    I just did following very simple example and ProxyDataContractResolver works as expected – graph of proxied entities with cycles was correctly serialized.

    using System;
    using System.Collections.Generic;
    using System.Data.Entity;
    using System.Data.Objects;
    using System.IO;
    using System.Linq;
    using System.Runtime.Serialization;
    
    namespace CFSerialization
    {
        class Program
        {
            static void Main(string[] args)
            {
                using (var context = new Context())
                {
                    context.Database.Delete();
                    context.Database.CreateIfNotExists();
    
                    context.Masters.Add(new Master
                        {
                            Name = "abc",
                            Details = new List<Detail>
                                {
                                    new Detail { Name = "a" },
                                    new Detail { Name = "b" },
                                    new Detail { Name = "c" }
                                }
                        });
                    context.SaveChanges();
                }
    
                using (var context = new Context())
                {
                    // This will get proxied Master
                    var master = context.Masters.First();
    
                    var serializer = new DataContractSerializer(typeof(Master), new DataContractSerializerSettings()
                        {
                            DataContractResolver = new ProxyDataContractResolver()
                        });
    
                    using (var stream = new MemoryStream())
                    {
                        // This will also lazy load all details
                        serializer.WriteObject(stream, master);
                        stream.Seek(0, SeekOrigin.Begin);
                        var newMaster = (Master)serializer.ReadObject(stream);
                    }
                }
            }
        }
    
        [DataContract(IsReference=true)]
        public class Master
        {
            [DataMember]
            public int Id { get; set; }
            [DataMember]
            public string Name { get; set; }
            [DataMember]
            public virtual ICollection<Detail> Details { get; set; }
        }
    
        [DataContract(IsReference=true)]
        public class Detail 
        {
            [DataMember]
            public int Id { get; set; }
            [DataMember]
            public string Name { get; set; }
            [DataMember]
            public virtual Master Master { get; set; }
        }
    
        public class Context : DbContext
        {
            public DbSet<Master> Masters { get; set; }
        }
    }
    

    There must be something more complicated in your model to break the functionality – are all your entities marked with DataContract(IsReference=true)?

    Note: I tested it in .NET 4.5.

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

Sidebar

Related Questions

I am using SQL Azure as database with code first technique of Entity framework
Can I serialize POCO classes? I'm using the C# POCO entity generator. I tried
I want to serialize an Entity Framework Self-Tracking Entities full object graph (parent +
Okay this could very likely be a silly question. I am using Entity Framework
I'm using ASP.NET Web API with Entity Framework. I changed my default serializer to
I have an MVC-3 (RC1) application using Entity Framework 4. I wish to return
I have an ASP.NET 4 web app that is using the Entity Framework to
I am using a domain model generated from a db with entity framework. How
I'm trying to model a somewhat non-standard relationship using .NET Entity Framework 4 for
I am using the DataContractSerializer to serialize EF4 objects to xml if there are

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.