Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用Mongo c#驱动程序反序列化继承的对象_C#_Mongodb_Asp.net Core_Mongodb .net Driver - Fatal编程技术网

无法使用Mongo c#驱动程序反序列化继承的对象

无法使用Mongo c#驱动程序反序列化继承的对象,c#,mongodb,asp.net-core,mongodb-.net-driver,C#,Mongodb,Asp.net Core,Mongodb .net Driver,我正在使用一些Asp.Net身份验证功能 然后我想扩展与我最初为我的项目创建的用户类型一起存在的MongoIdentityUser,因此我尝试从该类继承并创建一个以MongoIdentityUser为基类的类 如果我尝试查询存储了一个MongoIdentityUser的集合,并尝试将其反序列化为MongoIdentityUser,我会将该项取出,因此成功 但如果我尝试将其反序列化为一个继承的MongoDBUser类,则会出现以下异常: 难道不可能扩展我想要的类吗?另外,这个异常是非常无用的,不

我正在使用一些Asp.Net身份验证功能

然后我想扩展与我最初为我的项目创建的用户类型一起存在的
MongoIdentityUser
,因此我尝试从该类继承并创建一个以
MongoIdentityUser
为基类的类

如果我尝试查询存储了一个
MongoIdentityUser
的集合,并尝试将其反序列化为
MongoIdentityUser
,我会将该项取出,因此成功

但如果我尝试将其反序列化为一个继承的
MongoDBUser
类,则会出现以下异常:

难道不可能扩展我想要的类吗?另外,这个异常是非常无用的,不知道为什么它没有给我一个更详细的异常

json对象如下所示

{
    "_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
}

在最新版本的框架

IMHO中修复了此问题,您忘记使用类似于
BsonClassMap.LookupClassMap(typeof(User))
;)的东西注册派生类@shA.t但这不会只给我MongoEntityUser属性或Users属性,而不是两个类属性吗?这不是关于属性的,这是关于MongoDB可以基于它们进行序列化的类(read;)。Dit没有帮助,通常我也会得到一个映射错误,但是驱动程序中的这个nullreference异常似乎是错误的异常表示反序列化的结果为null,并且您不能为null对象调用
.ToList()
方法,Bson序列化器需要知道您的所有类;)。