-
Type:
Bug
-
Resolution: Done
-
Priority:
Major - P3
-
None
-
Affects Version/s: 1.8.2
-
Component/s: None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
-
None
The NUnit test below will throw a E1100 duplicate key error
using MongoDB.Bson;
using MongoDB.Driver;
using NUnit.Framework;
namespace MongoDB.BsonUnitTests.Jira
{
[TestFixture]
public class ReadOnlyIdTests
{
public class ReadOnlyIdFieldClass
{
public readonly int Id = 1;
public int id = 1;
}
[Test]
public void TestSerialization()
{
var obj1 = new ReadOnlyIdFieldClass();
obj1.id = 1;
var obj2 = new ReadOnlyIdFieldClass();
obj2.id = 2;
var client = new MongoClient();
var coll = client.GetServer().GetDatabase("foo").GetCollection<ReadOnlyIdFieldClass>("bar");
coll.Insert(obj1);
coll.Insert(obj2);
}
}
}
The fix is to either skip readonly fields as part of NameIdMemberConvention or implement it as a MemberMapConvention