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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:56:56+00:00 2026-05-23T16:56:56+00:00

I’m getting the following error when retrieving a document from MongoDB: Unable to determine

  • 0

I’m getting the following error when retrieving a document from MongoDB:

“Unable to determine actual type of
object to deserialize. NominalType is
System.Object and BsonType is Array.”

The object that I’m serializing has a Dictionary<string, object> property. I can put a simple string in the Dictionary and pull it out without getting an error, but if there is a List<string> then I get the deserialization error.

I’m using the official c# driver (v 1.1). I can query the document just fine using Mongo shell, so I’m pretty it’s an issue with MongoDB.Bson.

Any suggestions/workarounds?

Code sample as requested:

Example object being saved to MongoDB:

public class WebUser
{
  public int _id;
  private DateTime startTime;
  private DateTime stopTime;
  private string browser;
  private string sessionID;
  private string ip;
  public List<PageView> PageViews;
  public Dictionary<string, Object> Session;

  public Save(){/*Data access code here*/}
  public static Single(int id){/*Data access code here*/}
}

Data Access Code:

public T Single<T>(int id) where T : class, new()
{
  var server = MongoServer.Create(ConnectionString);
  var db = server.GetDatabase(DBName);
  var collection = db.GetCollection<T>(typeof(T).Name);   
  var value = collection.FindOneById(id);
  server.Disconnect();
  return value;
 }

This works just fine:

var wu = WebUser.single(1);
wu.Session.Add("string key", "value");
wu.Session.Add("int key", 1);
wu.Save();
wu = WebUser.single(1);

This is where I get an error:

var wu = WebUser.single(1);
wu.Session.Add("list of values", new List<string>() { "yada", "yada 2", "yada 3" });
wu.Save();
//deserialize error on the retrieve below
wu = WebUser.single(1);
  • 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-05-23T16:56:57+00:00Added an answer on May 23, 2026 at 4:56 pm

    I think the following simple example reproduces the issue. Use class:

    public class C {
        public ObjectId Id;
        public object Obj;
    }
    

    and the following test code:

    collection.RemoveAll();
    var c = new C { Obj = new int[] { 1, 2, 3 } };
    collection.Insert(c);
    
    var r = collection.FindOneAs<C>(); // fails
    

    The problem is that the document was serialized as:

    > db.test.find()
    { "_id" : ObjectId("4e15b931e447ad6a54eb0114"), "Obj" : [ 1, 2, 3 ] }
    >
    

    and the value for “Obj” has no type information, so the deserializer doesn’t know what class to instantiate for “Obj”.

    I’ve create a JIRA ticket for this:

    https://jira.mongodb.org/browse/CSHARP-263

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am currently running into a problem where an element is coming back from
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
i got an object with contents of html markup in it, for example: string
I have a bunch of posts stored in text files formatted in yaml/textile (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.