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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:29:29+00:00 2026-06-11T18:29:29+00:00

I am using MongoDB to deserialise a document into a C# object and am

  • 0

I am using MongoDB to deserialise a document into a C# object and am having issues with ObjectID fields. This is the error I am getting:

Required element ‘LayoutId’ for property ‘LayoutId’ of class MyProject.Data.MyDocument is missing.

Which (if it doesn’t look odd anyways) does make sense because the LayoutId field IS specified:

using System;
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;

namespace MyProject.Data
{
  public class MyDocument
  {

    public override ObjectId Id { get; set; }

    [BsonRequired]
    public String Name { get; set; }

    [BsonRequired]
    public ObjectId LayoutId { get; set; }

  }
}

And its populated in the database:

enter image description here

So what other aspects of the serialisation process could prevent this element from being populated? Is there a bug in a particular version of the driver? Am I using the right data type?

It should also be noted that:

  • this document was used to populate that value in the database, so it appears that only deserialisation is an issue and serialisation is fine.
  • there are other documents in the same library which have the same issue.
  • there are mongo documents/contracts in the same solution but in a different library which do NOT seem to have the same prolem,
  • 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-11T18:29:30+00:00Added an answer on June 11, 2026 at 6:29 pm

    Thank you Craig for attempting to solve this problem. It turns out that I had not written the question properly.

    The problem was that I was calling “SetFields()” on the result, and the fields I was requesting did not include “LayoutId”. I would have expected a more descriptive error from the driver though.

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

Sidebar

Related Questions

Using mongodb with the NoRM driver I have this document: { _id : ObjectId(0758030341b870c019591900),
Using MongoDB, I'm having trouble adding en element to an Array when the array
I'm using mongodb 2.1 and how to translate this query into php db.counter.aggregate([ {
Im using mongodb + java. I tried to insert a new document into an
I'm trying to persist an object into a MongoDB, using the following bit of
I'm using MongoDB and Spring 3. I have the following domain object: @Document(collection =
I am using mongoDB for a new project at work and I got into
I'm using MongoDB to hold a collection of documents. Each document has an _id
I'm using MongoDB but I'm not really using it's dynamic fields capabilities field :fb_followers
I am currently using MongoDB's MapReduce to generate hourly ad view counts like this:

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.