-
Type: Bug
-
Resolution: Duplicate
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.4.3
-
Component/s: Serialization
-
None
-
Environment:.NET 4.5.1. We are upgrading the driver from v1.8.x. Project infrastructure does not allow generics yet so cast to object is used as a workaround.
-
(copied to CRM)
Trying to build update command with $set operator using UpdateDefinitionBuilder. However it does not serialize string arrays when they are casted to object. Instead it gives "(Collection)".
This works fine in v2.4.2. But is broken in v2.4.3.
Looks like it works fine with other arrays too. Problem is just with string arrays.
Here is simple console app to show to issue:
class Program { static void Main(string[] args) { var updateBuilder = new UpdateDefinitionBuilder<Item>(); var fooValue = new List<int> { 11, 22, 33 }; var barValue = new List<string> { "Bar1", "Bar2", "Bar3" }; Console.WriteLine(Render(updateBuilder.Set<List<int>>(x => x.Foo, fooValue))); Console.WriteLine(Render(updateBuilder.Set<List<string>>(x => x.Bar, barValue))); Console.WriteLine(Render(updateBuilder.Set<object>(x => x.Foo, fooValue))); Console.WriteLine(Render(updateBuilder.Set<object>(x => x.Bar, barValue))); Console.ReadKey(); } public class Item { public Guid Id { get; set; } public List<int> Foo { get; set; } public List<string> Bar { get; set; } } private static string Render(UpdateDefinition<Item> definition) { var settings = new MongoCollectionSettings(); var serializer = settings.SerializerRegistry.GetSerializer<Item>(); return definition.Render(serializer, settings.SerializerRegistry).ToString(); } }
Output with v2.4.2:
{ "$set" : { "Foo" : [11, 22, 33] } } { "$set" : { "Bar" : ["Bar1", "Bar2", "Bar3"] } } { "$set" : { "Foo" : { "_t" : "System.Collections.Generic.List`1[System.Int32]", "_v" : [11, 22, 33] } } } { "$set" : { "Bar" : { "_t" : "System.Collections.Generic.List`1[System.String]", "_v" : ["Bar1", "Bar2", "Bar3"] } } }
Output with v2.4.3:
{ "$set" : { "Foo" : [11, 22, 33] } } { "$set" : { "Bar" : ["Bar1", "Bar2", "Bar3"] } } { "$set" : { "Foo" : { "_t" : "System.Collections.Generic.List`1[System.Int32]", "_v" : [11, 22, 33] } } } { "$set" : { "Bar" : "(Collection)" } }
- duplicates
-
CSHARP-2215 Update.Set can generate invalid $set when type of value does not match type of POCO
- Closed
- related to
-
CSHARP-2215 Update.Set can generate invalid $set when type of value does not match type of POCO
- Closed