Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
193
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. Newtonsoft.Json.JsonSerializationException: 'Error converting value "5b5b4df5b8e2e208efb2c0da" to type 'MongoDB.Bson.ObjectId'. Path 'Id', line 1, position 64.'
  2. InvalidCastException: Invalid cast from 'System.String' to 'MongoDB.Bson.ObjectId'.
  3.  
  4. public class TblUser
  5. {
  6. public ObjectId Id { get; set; }
  7. public string Username { get; set; }
  8. public string Password { get; set; }
  9. }
  10.  
  11. public static string ObjToStr(Object obj)
  12. {
  13. return JsonConvert.SerializeObject(obj);
  14. }
  15.  
  16. public static T StrToObj<T>(string str)
  17. {
  18. return JsonConvert.DeserializeObject<T>(str);
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement