[CSHARP-239] Cant' map a class with a member of the same Type. Created: 04/Jun/11  Updated: 02/Apr/15  Resolved: 08/Jun/11

Status: Closed
Project: C# Driver
Component/s: None
Affects Version/s: 1.0
Fix Version/s: 1.0

Type: Bug Priority: Major - P3
Reporter: Luigi Bertazzo Assignee: Robert Stam
Resolution: Done Votes: 0
Labels: c#, mapping
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows


Attachments: Zip Archive TestSerializeRecursiveClass.zip    

 Description   

If a class declare a member of the same class Type you get a mapping error.

Possible change in BsonClassMap.cs (all tests passed):

/// <summary>
/// Registers a class map.
/// </summary>
/// <param name="classMap">The class map.</param>
public static void RegisterClassMap(
BsonClassMap classMap
) {
lock (BsonSerializer.ConfigLock) {
// note: class maps can NOT be replaced (because derived classes refer to existing instance)
// classMaps.Add(classMap.ClassType, classMap); ORIGINAL
if (!classMaps.ContainsKey(classMap.ClassType))

{ classMaps.Add(classMap.ClassType, classMap); BsonDefaultSerializer.RegisterDiscriminator(classMap.ClassType, classMap.Discriminator); }

}
}



 Comments   
Comment by Robert Stam [ 08/Jun/11 ]

No worries. Thanks for letting us know you got it working.

Comment by Luigi Bertazzo [ 07/Jun/11 ]

Not a bug, my fault in mapping the class: i was calling BsonClassMap.LookupClassMap(typeof(A)) inside BsonClassMap.RegisterClassMap<A> while setting some serialization options using IBsonSerializationOptions on the member with the same type A of the class being mapped. Really sorry to waste your time, thanks for your attention.

Comment by Robert Stam [ 06/Jun/11 ]

I am unable to reproduce this. See the attached solution (TestSerializeRecursiveClass.zip).

Can you provide more information? What does your class look like? What error are you getting?

Thanks.

Comment by Robert Stam [ 06/Jun/11 ]

Attempt to reproduce.

Generated at Wed Feb 07 21:36:14 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.