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

  • Home
  • SEARCH
  • 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 8514467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:52:39+00:00 2026-06-11T04:52:39+00:00

I am trying to serialize an object graph. It works up until I have

  • 0

I am trying to serialize an object graph. It works up until I have to load a child entity that is an entity set. The system won’t allow it to serialize… it gives me this error:

Type ‘System.Data.Linq.EntitySet`1[NetDataContractSerializerTest.JobService]’ cannot be serialized. Consider marking it with the DataContractAttribute attribute, and marking all of its members you want serialized with the DataMemberAttribute attribute. If the type is a collection, consider marking it with the CollectionDataContractAttribute. See the Microsoft .NET Framework documentation for other supported types.

Here is the code I am using:

        DataClasses1DataContext dataAccessContext = new DataClasses1DataContext();
        MemoryStream stream = new MemoryStream();

        DataLoadOptions dataloadOptions = new DataLoadOptions();
        dataloadOptions.LoadWith<JN>(j => j.nh);  
        dataloadOptions.LoadWith<JN>(j => j.JobServices);// this is the child entity set

        dataAccessContext.LoadOptions = dataloadOptions;

        var jn= dataAccessContext.JN.Where(j => j.LocnID.Trim() == "HT").ToList();
        var netDataContractSerializer = new NetDataContractSerializer();
        netDataContractSerializer.Serialize(stream, jn); //the error happens here

If I remove the

dataloadOptions.LoadWith(j => j.JobServices)

the data will serialize with the JN and nh tables intact. But when I put

dataloadOptions.LoadWith(j => j.JobServices)

back in I get the error.

I personally think that it wants me to add a ToList() to the JobServices, unfortunately I can’t do

dataloadOptions.LoadWith(j => j.JobServices.ToList())

This throws an error.

Any ideas?

  • 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-11T04:52:41+00:00Added an answer on June 11, 2026 at 4:52 am

    Well well well…. look what I found….. This seemed to serialize and deserialize my stuff just fine. Instead of using NetDataContractSerializer.Serialize() to it, this guy wrote serialize and deserialize functions that used DataContractSerializer, XMLWriter and XMLReader

    Check the link below

    http://www.codeproject.com/Tips/47054/How-to-serialize-list-of-linq-entities-ex-from-DBM

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

Sidebar

Related Questions

I have an XML file that I'm trying to serialize into an object. Some
I'm trying to serialize an object that have a duplicate node name using C#,
I'm trying to serialize an object to XML that has a number of properties,
I have been trying to serialize a pretty big object. This object uses dictionaries
I'm trying to make a genric code to serialize and deserialize any object that
I have a simple object I'm trying to serialize using DataContractSerializer. In my unit
I have a simple JSON object graph I'm trying to render using a Mustache
I have an custom object I'm trying to serialize using Protobuf-net and the following
I'm trying to serialize an object as XML and have been using a little
I have a pretty sizeable object graph that I have serialized to a file

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.