title: Cannot deserialize string from BsonType ObjectId in MongoDb C#
body: <p>I am getting error <code>"Cannot deserialize string from BsonType ObjectId"</code> while trying to get all the record from MongoDb in C# WebAPI</p>
  
  <p>My Id is</p>
  
  <pre><code>[BsonId]
  public string Id { get; set; }
  </code></pre>
  
  <p>After Changing it to</p>
  
  <pre><code>[BsonRepresentation(BsonType.ObjectId)] 
  public string Id { get; set; }
  </code></pre>
  
  <p>its working fine</p>
  
  <p>But while i'm calling post method, its giving me different error</p>
  
  <pre><code>"'d05e139c-3a48-4213-bd89-eba0c22c3c6f' is not a valid 24 digit hex string."
  </code></pre>
  
  <p>How can solve this problem</p>
  
  <p>My Model is:</p>
  
  <pre><code>public class EstablishmentDetails
  {
  
      [BsonRepresentation(BsonType.ObjectId)] 
      public string Id { get; set; }
      public string EstablishmentName { get; set; }
      public string EstablishmentType { get; set; }
      public string Address { get; set; }
      public string City { get; set; }
      public int StateID { get; set; }
      public Int32 PIN { get; set; }
      public Int64 PhoneNumber { get; set; }
      public string EmailID { get; set; }
      public bool Published { get; set; }
      public string CreatedDate { get; set; }
      public string ModifiedDate { get; set; }
  }
  </code></pre>
  
  <p>My repository fro Get method</p>
  
  <pre><code>public IEnumerable&lt;EstablishmentDetails&gt; GetAllEstablishmentDetails()
      {
          if (Convert.ToInt32(mCollection.Count()) &gt; 0)
          {
              var EstablishmentDetailsCollection = mCollection.FindAllAs(typeof(EstablishmentDetails));
  
              if (EstablishmentDetailsCollection.Count() &gt; 0)
              {
                  foreach (EstablishmentDetails item in EstablishmentDetailsCollection)
                  {
                      establishmentDetails.Add(item);
                  }
              }
          }
          var results = establishmentDetails.AsQueryable();
          return results;
      }
  </code></pre>
  
  <p>My repository for Post method</p>
  
  <pre><code>public EstablishmentDetails Add(EstablishmentDetails ed)
      {
          if (string.IsNullOrEmpty(ed.Id))
          {
              ed.Id = Guid.NewGuid().ToString();
          }
  
          mCollection.Save(ed);
          return ed;
      }
  </code></pre>