Asp.net web api MongoDB C#驱动程序和MVC4 webapi。json序列化中的问题

Asp.net web api MongoDB C#驱动程序和MVC4 webapi。json序列化中的问题,asp.net-web-api,mongodb-.net-driver,Asp.net Web Api,Mongodb .net Driver,我正在使用MongoDB提供的C#驱动程序,将MongoDB数据库与MVC4 WebAPI一起使用。我对序列化有一个问题。我得到以下错误 "ExceptionMessage=Error getting value from '__emptyInstance' on 'MongoDB.Bson.ObjectId'" 如果我在HTTP请求中将内容类型更改为xml,它就可以正常工作。我将感谢任何帮助 我复制了下面的模型 public class Subscriber { public

我正在使用MongoDB提供的C#驱动程序,将MongoDB数据库与MVC4 WebAPI一起使用。我对序列化有一个问题。我得到以下错误

    "ExceptionMessage=Error getting value from '__emptyInstance' on 'MongoDB.Bson.ObjectId'"
如果我在HTTP请求中将内容类型更改为xml,它就可以正常工作。我将感谢任何帮助

我复制了下面的模型

public class Subscriber
{
    public ObjectId _id;

    public long SubscriberId { get; set; }

    public Name Name { get; set; }

    public Address Address { get; set; }

    public string Phone { get; set; }

    public ICollection<Subscription> Subscription { get; set; }


    public Subscriber()
    {
        Name = new Name();
        Address = new Address();
        Subscription = new Collection<Subscription>();
}
}

参考资料:

对于尝试回答中提到的“解决方案”的人:它根本不起作用


请将标记的答案签入

你能分享一下你试图序列化为JSON的类型是什么样子的吗?另外,从错误中可以看出它是
MongoDB.Bson.ObjectId
,它应该是一个Bson格式化程序吗?Filip在这里有一个创建BSON格式化程序的例子:你能分享你的模型吗?我复制了上面的模型。问题是ObjectId没有被序列化。谢谢
[BsonId]
[BsonRepresentation(BsonType.ObjectId)]
public string _id;