Mech0z Mech0z - 4 years ago 147
C# Question

Cant deserialize inherited object with Mongo c# driver

I am using

nuget package to get some Asp.Net Identity features into my project.

Then I want to extend the
MongoIdentityUser
that exists with the User type I originally created for my project, so I tried to inherit from that class and create my User Class that has
MongoIdentityUser
as its base class.

If I try to query my collection where I have one
MongoIdentityUser
stored and try to deserialize it into
MongoIdentityUser
I get that one item out, so success.

But if I try to deserialize it into My User which is just an inherited class of
MongoDBUser
I get this exception:
Exception

Is it not possible to extent a class like that I want? Also the exception is pretty useless, not sure why its not giving me a more detailed exception

The json object looks like this

{
"_id": "dat@email.com",
"userName": "dat@email.com",
"normalizedUserName": "dat@email.com",
"email": {
"value": "dat@email.com",
"confirmationRecord": null,
"normalizedValue": "dat@email.com"
},
"phoneNumber": null,
"passwordHash": "xxx",
"securityStamp": "87242bb7-2a09-4905-ba61",
"isTwoFactorEnabled": false,
"claims": [],
"logins": [],
"accessFailedCount": 0,
"isLockoutEnabled": true,
"lockoutEndDate": null,
"createdOn": {
"instant": {
"$date": "2016-11-13T17:05:59.487Z"
}
},
"deletedOn": null
}

Answer Source
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download