1

I am using AspNetCore.Identity.MongoDB 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
}
shA.t
  • 16,580
  • 5
  • 54
  • 111
Mech0z
  • 3,627
  • 6
  • 49
  • 85
  • IMHO, you forgot to register your derived class by using something like `BsonClassMap.LookupClassMap(typeof(User))` ;). – shA.t Dec 18 '16 at 12:09
  • @shA.t but wont that only give me only either MongoIdentityUser properties or Users properties and not both classes properties? – Mech0z Dec 18 '16 at 15:39
  • This is not about properties this is about classes that MongoDB can serialize based on them read [this for more](http://mongodb.github.io/mongo-csharp-driver/2.0/reference/bson/mapping/) ;). – shA.t Dec 18 '16 at 16:02
  • Dit not help, also normally I would get a mapping error, but this nullreference exception in the driver seems wrong – Mech0z Dec 18 '16 at 19:16
  • The exception said that result of deserializing is null and you can't call `.ToList()` method for a null object, Bson serializer needs to know all your classes ;). – shA.t Dec 19 '16 at 09:00

1 Answers1

1

Fixed in the latest release of the framework https://github.com/tugberkugurlu/AspNetCore.Identity.MongoDB/releases/tag/1.0.0-rc3

Mech0z
  • 3,627
  • 6
  • 49
  • 85