<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:35:48 UTC 2024

It is possible to restrict the fields that are returned in this document by specifying the 'field' parameter in your request.
For example, to request only the issue key and summary append 'field=key&field=summary' to the URL of your request.
-->
<rss version="0.92" >
<channel>
    <title>MongoDB Jira</title>
    <link>https://jira.mongodb.org</link>
    <description>This file is an XML representation of an issue</description>
    <language>en-us</language>    <build-info>
        <version>9.7.1</version>
        <build-number>970001</build-number>
        <build-date>13-04-2023</build-date>
    </build-info>


<item>
            <title>[CSHARP-100] CSharp driver exception when Saving a an object with an IList&lt;T&gt; property as opposed to List&lt;T&gt;</title>
                <link>https://jira.mongodb.org/browse/CSHARP-100</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Long story short, if I call MongoCollection.Save&amp;lt;T&amp;gt;() on a class with&lt;br/&gt;
an IList&amp;lt;T&amp;gt; property it throws an exception. If I change it it List&amp;lt;T&amp;gt;&lt;br/&gt;
it does not.&lt;/p&gt;

&lt;p&gt;Long Explanation where I take actual code, and scrub it:&lt;/p&gt;

&lt;p&gt;So I have class that kinda looks like this:&lt;/p&gt;

&lt;p&gt;   &lt;span class=&quot;error&quot;&gt;&amp;#91;DataContract&amp;#93;&lt;/span&gt;&lt;br/&gt;
   public class ChildClass : ParentClass&lt;br/&gt;
   {&lt;br/&gt;
       &lt;span class=&quot;error&quot;&gt;&amp;#91;BsonIgnoreIfNull&amp;#93;&lt;/span&gt;&lt;br/&gt;
       &lt;span class=&quot;error&quot;&gt;&amp;#91;DataMember(Order = 1)&amp;#93;&lt;/span&gt;&lt;br/&gt;
       &lt;span class=&quot;error&quot;&gt;&amp;#91;BsonKnownTypes(typeof(List&amp;lt;SomeClass&amp;gt;))&amp;#93;&lt;/span&gt;&lt;br/&gt;
       public IList&amp;lt;SomeClass&amp;gt; SomeProperty &lt;/p&gt;
{ get; set; }&lt;br/&gt;
   }&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;
And then I do something like this:&lt;br/&gt;
&lt;br/&gt;
var obj = new ChildClass{&lt;br/&gt;
  SomeProperty = new List&amp;lt;SomeClass&amp;gt;();&lt;br/&gt;
};&lt;br/&gt;
_db&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;someCollection&amp;quot;&amp;#93;&lt;/span&gt;.Save(obj, SafeMode.True);&lt;br/&gt;
&lt;br/&gt;
Then I get the following&lt;br/&gt;
GenericArraySerializer cannot be used with type:&lt;br/&gt;
System.Collections.Generic.IList`1[[SomeClass, SomeAssembly&lt;br/&gt;
Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]&lt;br/&gt;
 at MongoDB.Bson.DefaultSerializer.GenericArraySerializer.VerifyNominalType(Type&lt;br/&gt;
nominalType) in d:&lt;br class=&quot;atl-forced-newline&quot; /&gt;justin&apos;s&lt;br/&gt;
projects\\mongo-csharp\\Bson\\DefaultSerializer\\Serializers&lt;br class=&quot;atl-forced-newline&quot; /&gt;GenericArraySerializer.cs:line&lt;br/&gt;
113\r\n   at MongoDB.Bson.DefaultSerializer.GenericArraySerializer.Serialize(BsonWriter&lt;br/&gt;
bsonWriter, Type nominalType, Object value, Boolean serializeIdFirst)&lt;br/&gt;
in d:&lt;br class=&quot;atl-forced-newline&quot; /&gt;justin&apos;s&lt;br/&gt;
projects\\mongo-csharp\\Bson\\DefaultSerializer\\Serializers&lt;br class=&quot;atl-forced-newline&quot; /&gt;GenericArraySerializer.cs:line&lt;br/&gt;
83\r\n   at MongoDB.Bson.DefaultSerializer.BsonClassMapSerializer.SerializeMember(BsonWriter&lt;br/&gt;
bsonWriter, Object obj, BsonMemberMap memberMap) in d:&lt;br class=&quot;atl-forced-newline&quot; /&gt;justin&apos;s&lt;br/&gt;
projects\\mongo-csharp\\Bson\\DefaultSerializer&lt;br class=&quot;atl-forced-newline&quot; /&gt;BsonClassMapSerializer.cs:line&lt;br/&gt;
221\r\n   at MongoDB.Bson.DefaultSerializer.BsonClassMapSerializer.Serialize(BsonWriter&lt;br/&gt;
bsonWriter, Type nominalType, Object value, Boolean serializeIdFirst)&lt;br/&gt;
in d:&lt;br class=&quot;atl-forced-newline&quot; /&gt;justin&apos;s&lt;br/&gt;
projects\\mongo-csharp\\Bson\\DefaultSerializer&lt;br class=&quot;atl-forced-newline&quot; /&gt;BsonClassMapSerializer.cs:line&lt;br/&gt;
181\r\n   at MongoDB.Bson.Serialization.BsonSerializer.Serialize(BsonWriter&lt;br/&gt;
bsonWriter, Type nominalType, Object value, Boolean serializeIdFirst)&lt;br/&gt;
in d:&lt;br class=&quot;atl-forced-newline&quot; /&gt;justin&apos;s&lt;br/&gt;
projects\\mongo-csharp\\Bson\\Serialization&lt;br class=&quot;atl-forced-newline&quot; /&gt;BsonSerializer.cs:line&lt;br/&gt;
245\r\n   at MongoDB.Bson.Serialization.BsonSerializer.Serialize(BsonWriter&lt;br/&gt;
bsonWriter, Type nominalType, Object value) in d:&lt;br class=&quot;atl-forced-newline&quot; /&gt;justin&apos;s&lt;br/&gt;
projects\\mongo-csharp\\Bson\\Serialization&lt;br class=&quot;atl-forced-newline&quot; /&gt;BsonSerializer.cs:line&lt;br/&gt;
229\r\n   at MongoDB.Bson.DefaultSerializer.EnumerableSerializer`1.Serialize(BsonWriter&lt;br/&gt;
bsonWriter, Type nominalType, Object value, Boolean serializeIdFirst)&lt;br/&gt;
in d:&lt;br class=&quot;atl-forced-newline&quot; /&gt;justin&apos;s&lt;br/&gt;
projects\\mongo-csharp\\Bson\\DefaultSerializer\\Serializers&lt;br class=&quot;atl-forced-newline&quot; /&gt;CollectionSerializersGeneric.cs:line&lt;br/&gt;
89\r\n   at MongoDB.Bson.DefaultSerializer.BsonClassMapSerializer.SerializeMember(BsonWriter&lt;br/&gt;
bsonWriter, Object obj, BsonMemberMap memberMap) in d:&lt;br class=&quot;atl-forced-newline&quot; /&gt;justin&apos;s&lt;br/&gt;
projects\\mongo-csharp\\Bson\\DefaultSerializer&lt;br class=&quot;atl-forced-newline&quot; /&gt;BsonClassMapSerializer.cs:line&lt;br/&gt;
221\r\n   at MongoDB.Bson.DefaultSerializer.BsonClassMapSerializer.Serialize(BsonWriter&lt;br/&gt;
bsonWriter, Type nominalType, Object value, Boolean serializeIdFirst)&lt;br/&gt;
in d:&lt;br class=&quot;atl-forced-newline&quot; /&gt;justin&apos;s&lt;br/&gt;
projects\\mongo-csharp\\Bson\\DefaultSerializer&lt;br class=&quot;atl-forced-newline&quot; /&gt;BsonClassMapSerializer.cs:line&lt;br/&gt;
181\r\n   at MongoDB.Bson.Serialization.BsonSerializer.Serialize(BsonWriter&lt;br/&gt;
bsonWriter, Type nominalType, Object value, Boolean serializeIdFirst)&lt;br/&gt;
in d:&lt;br class=&quot;atl-forced-newline&quot; /&gt;justin&apos;s&lt;br/&gt;
projects\\mongo-csharp\\Bson\\Serialization&lt;br class=&quot;atl-forced-newline&quot; /&gt;BsonSerializer.cs:line&lt;br/&gt;
245\r\n   at MongoDB.Bson.Serialization.BsonSerializer.Serialize(BsonWriter&lt;br/&gt;
bsonWriter, Type nominalType, Object value) in d:&lt;br class=&quot;atl-forced-newline&quot; /&gt;justin&apos;s&lt;br/&gt;
projects\\mongo-csharp\\Bson\\Serialization&lt;br class=&quot;atl-forced-newline&quot; /&gt;BsonSerializer.cs:line&lt;br/&gt;
229\r\n   at MongoDB.Bson.DefaultSerializer.EnumerableSerializer`1.Serialize(BsonWriter&lt;br/&gt;
bsonWriter, Type nominalType, Object value, Boolean serializeIdFirst)&lt;br/&gt;
in d:&lt;br class=&quot;atl-forced-newline&quot; /&gt;justin&apos;s&lt;br/&gt;
projects\\mongo-csharp\\Bson\\DefaultSerializer\\Serializers&lt;br class=&quot;atl-forced-newline&quot; /&gt;CollectionSerializersGeneric.cs:line&lt;br/&gt;
89\r\n   at MongoDB.Bson.DefaultSerializer.BsonClassMapSerializer.SerializeMember(BsonWriter&lt;br/&gt;
bsonWriter, Object obj, BsonMemberMap memberMap) in d:&lt;br class=&quot;atl-forced-newline&quot; /&gt;justin&apos;s&lt;br/&gt;
projects\\mongo-csharp\\Bson\\DefaultSerializer&lt;br class=&quot;atl-forced-newline&quot; /&gt;BsonClassMapSerializer.cs:line&lt;br/&gt;
221\r\n   at MongoDB.Bson.DefaultSerializer.BsonClassMapSerializer.Serialize(BsonWriter&lt;br/&gt;
bsonWriter, Type nominalType, Object value, Boolean serializeIdFirst)&lt;br/&gt;
in d:&lt;br class=&quot;atl-forced-newline&quot; /&gt;justin&apos;s&lt;br/&gt;
projects\\mongo-csharp\\Bson\\DefaultSerializer&lt;br class=&quot;atl-forced-newline&quot; /&gt;BsonClassMapSerializer.cs:line&lt;br/&gt;
181\r\n   at MongoDB.Bson.Serialization.BsonSerializer.Serialize(BsonWriter&lt;br/&gt;
bsonWriter, Type nominalType, Object value, Boolean serializeIdFirst)&lt;br/&gt;
in d:&lt;br class=&quot;atl-forced-newline&quot; /&gt;justin&apos;s&lt;br/&gt;
projects\\mongo-csharp\\Bson\\Serialization&lt;br class=&quot;atl-forced-newline&quot; /&gt;BsonSerializer.cs:line&lt;br/&gt;
245\r\n   at MongoDB.Bson.Serialization.BsonSerializer.Serialize&lt;span class=&quot;error&quot;&gt;&amp;#91;T&amp;#93;&lt;/span&gt;(BsonWriter&lt;br/&gt;
bsonWriter, T value, Boolean serializeIdFirst) in d:&lt;br class=&quot;atl-forced-newline&quot; /&gt;justin&apos;s&lt;br/&gt;
projects\\mongo-csharp\\Bson\\Serialization&lt;br class=&quot;atl-forced-newline&quot; /&gt;BsonSerializer.cs:line&lt;br/&gt;
221\r\n   at MongoDB.Driver.Internal.MongoUpdateMessage`2.WriteBody()&lt;br/&gt;
in d:&lt;br class=&quot;atl-forced-newline&quot; /&gt;justin&apos;s&lt;br/&gt;
projects\\mongo-csharp\\Driver\\Internal&lt;br class=&quot;atl-forced-newline&quot; /&gt;MongoUpdateMessage.cs:line&lt;br/&gt;
58\r\n   at MongoDB.Driver.Internal.MongoRequestMessage.WriteToBuffer()&lt;br/&gt;
in d:&lt;br class=&quot;atl-forced-newline&quot; /&gt;justin&apos;s&lt;br/&gt;
projects\\mongo-csharp\\Driver\\Internal&lt;br class=&quot;atl-forced-newline&quot; /&gt;MongoRequestMessage.cs:line&lt;br/&gt;
81\r\n   at MongoDB.Driver.Internal.MongoConnection.SendMessage(MongoRequestMessage&lt;br/&gt;
message, SafeMode safeMode) in d:&lt;br class=&quot;atl-forced-newline&quot; /&gt;justin&apos;s&lt;br/&gt;
projects\\mongo-csharp\\Driver\\Internal&lt;br class=&quot;atl-forced-newline&quot; /&gt;MongoConnection.cs:line&lt;br/&gt;
324\r\n   at MongoDB.Driver.MongoCollection.Update&lt;span class=&quot;error&quot;&gt;&amp;#91;TQuery,TUpdate&amp;#93;&lt;/span&gt;(TQuery&lt;br/&gt;
query, TUpdate update, UpdateFlags flags, SafeMode safeMode) in&lt;br/&gt;
d:&lt;br class=&quot;atl-forced-newline&quot; /&gt;justin&apos;s projects\\mongo-csharp\\Driver\\Core&lt;br class=&quot;atl-forced-newline&quot; /&gt;MongoCollection.cs:line&lt;br/&gt;
662\r\n   at MongoDB.Driver.MongoCollection.Save&lt;span class=&quot;error&quot;&gt;&amp;#91;TDocument&amp;#93;&lt;/span&gt;(TDocument&lt;br/&gt;
document, SafeMode safeMode) in d:&lt;br class=&quot;atl-forced-newline&quot; /&gt;justin&apos;s&lt;br/&gt;
projects\\mongo-csharp\\Driver\\Core&lt;br class=&quot;atl-forced-newline&quot; /&gt;MongoCollection.cs:line 584\r\n&lt;br/&gt;
 at&lt;br/&gt;
... ... ... My Code .......&lt;br/&gt;
&lt;br/&gt;
&lt;br/&gt;
So the fix is as follows:&lt;br/&gt;
&lt;br/&gt;
   &lt;span class=&quot;error&quot;&gt;&amp;#91;DataContract&amp;#93;&lt;/span&gt;&lt;br/&gt;
   public class ChildClass : ParentClass&lt;br/&gt;
   {&lt;br/&gt;
       &lt;span class=&quot;error&quot;&gt;&amp;#91;BsonIgnoreIfNull&amp;#93;&lt;/span&gt;&lt;br/&gt;
       &lt;span class=&quot;error&quot;&gt;&amp;#91;DataMember(Order = 1)&amp;#93;&lt;/span&gt;&lt;br/&gt;
-       &lt;span class=&quot;error&quot;&gt;&amp;#91;BsonKnownTypes(typeof(List&amp;lt;SomeClass&amp;gt;))&amp;#93;&lt;/span&gt;&lt;br/&gt;
-       public IList&amp;lt;SomeClass&amp;gt; SomeProperty { get; set; }
&lt;p&gt;+      public List&amp;lt;SomeClass&amp;gt; SomeProperty &lt;/p&gt;
{ get; set; }
&lt;p&gt;   }&lt;/p&gt;</description>
                <environment>Visual Studio 2008</environment>
        <key id="13726">CSHARP-100</key>
            <summary>CSharp driver exception when Saving a an object with an IList&lt;T&gt; property as opposed to List&lt;T&gt;</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="3" iconUrl="https://jira.mongodb.org/images/icons/priorities/major.svg">Major - P3</priority>
                        <status id="6" iconUrl="https://jira.mongodb.org/images/icons/statuses/closed.png" description="The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.">Closed</status>
                    <statusCategory id="3" key="done" colorName="success"/>
                                    <resolution id="9">Done</resolution>
                                        <assignee username="robert@mongodb.com">Robert Stam</assignee>
                                    <reporter username="zippy1981">Justin Dearing</reporter>
                        <labels>
                    </labels>
                <created>Wed, 17 Nov 2010 19:21:43 +0000</created>
                <updated>Thu, 2 Apr 2015 18:27:37 +0000</updated>
                            <resolved>Wed, 17 Nov 2010 21:04:36 +0000</resolved>
                                    <version>0.9</version>
                                    <fixVersion>0.9</fixVersion>
                                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                <comments>
                            <comment id="20425" author="rstam" created="Wed, 17 Nov 2010 21:04:36 +0000"  >&lt;p&gt;Fixed. Also improved implementation of ArraySerializer (no Invoke any more).&lt;/p&gt;</comment>
                            <comment id="20423" author="zippy1981" created="Wed, 17 Nov 2010 20:35:23 +0000"  >&lt;p&gt;It took me a bit to understand your comment. I didn&apos;t know and IList&amp;lt;T&amp;gt; could hold an array, but the MSDN verified it. The problem for me is that WCF is the real culprit, I&apos;m passing a request contract to th&lt;/p&gt;

&lt;p&gt;I actually have no need to use IList&amp;lt;T&amp;gt; as opposed to List&amp;lt;T&amp;gt;, I was just trying to be all polymorphic and using the interface since that seemed like &quot;The Right Thing To Do&quot;&#8482;. So changing from IList&amp;lt;T&amp;gt; to List&amp;lt;T&amp;gt; is my quick workaround for me. Seeing this WCF behavior, and the implications, like SomeProperty.Add() throwing NotImplementedException(), I might end up sticking with List&amp;lt;T&amp;gt; for the long term.&lt;/p&gt;</comment>
                            <comment id="20419" author="rstam" created="Wed, 17 Nov 2010 20:05:03 +0000"  >&lt;p&gt;Was able to reproduce by adding these two lines:&lt;/p&gt;

&lt;p&gt;            obj = new ChildClass { SomeProperty = new [] &lt;/p&gt;
{ new SomeClass(), new SomeClass() }
&lt;p&gt; };&lt;br/&gt;
            collection.Save(obj, SafeMode.True);&lt;/p&gt;

&lt;p&gt;so an easy workaround while this gets fixed is to use Lists instead of arrays when initializing SomeProperty.&lt;/p&gt;</comment>
                            <comment id="20416" author="rstam" created="Wed, 17 Nov 2010 19:33:22 +0000"  >&lt;p&gt;I added a unit test for this (CSharp100Tests.cs. under DriverOnlineTests). You can mess with the unit test and see if you can make it fail. Perhaps I didn&apos;t duplicate your scenario faithfully enough.&lt;/p&gt;</comment>
                            <comment id="20415" author="rstam" created="Wed, 17 Nov 2010 19:29:22 +0000"  >&lt;p&gt;I tried to reproduce and wasn&apos;t able to.&lt;/p&gt;

&lt;p&gt;Here&apos;s part of the code I wrote:&lt;/p&gt;

&lt;p&gt;            collection.RemoveAll();&lt;br/&gt;
            var obj = new ChildClass &lt;/p&gt;
{ SomeProperty = null }
&lt;p&gt;;&lt;br/&gt;
            collection.Save(obj, SafeMode.True);&lt;br/&gt;
            obj = new ChildClass &lt;/p&gt;
{ SomeProperty = new
List&amp;lt;SomeClass&amp;gt;() }
&lt;p&gt;;&lt;br/&gt;
            collection.Save(obj, SafeMode.True);&lt;br/&gt;
            obj = new ChildClass &lt;/p&gt;
{ SomeProperty = new List&amp;lt;SomeClass&amp;gt;
{ new SomeClass() }
&lt;p&gt; };&lt;br/&gt;
            collection.Save(obj, SafeMode.True);&lt;br/&gt;
            obj = new ChildClass &lt;/p&gt;
{ SomeProperty = new List&amp;lt;SomeClass&amp;gt;
{ new SomeClass(), new SomeClass() }
&lt;p&gt; };&lt;br/&gt;
            collection.Save(obj, SafeMode.True);&lt;/p&gt;

&lt;p&gt;and here&apos;s what the collection looked like in the shell:&lt;/p&gt;

&lt;p&gt;&amp;gt; db.csharpxx.find()&lt;/p&gt;

{ &quot;_id&quot; : ObjectId(&quot;4ce42b7fe447ad36fc456185&quot;) }
{ &quot;_id&quot; : ObjectId(&quot;4ce42b7fe447ad36fc456186&quot;), &quot;SomeProperty&quot; : [ ] }
&lt;p&gt;{ &quot;_id&quot; : ObjectId(&quot;4ce42b7fe447ad36fc456187&quot;), &quot;SomeProperty&quot; :&lt;br/&gt;
[ { } ] }&lt;br/&gt;
{ &quot;_id&quot; : ObjectId(&quot;4ce42b7fe447ad36fc456188&quot;), &quot;SomeProperty&quot; :&lt;br/&gt;
[ { }, { } ] } &lt;/p&gt;</comment>
                    </comments>
                    <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_15850" key="com.atlassian.jira.plugins.jira-development-integration-plugin:devsummary">
                        <customfieldname>Development</customfieldname>
                        <customfieldvalues>
                            
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    <customfield id="customfield_12550" key="com.pyxis.greenhopper.jira:gh-lexo-rank">
                        <customfieldname>Rank</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>2|hrh9ov:</customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                <customfield id="customfield_10558" key="com.pyxis.greenhopper.jira:gh-global-rank">
                        <customfieldname>Rank (Obsolete)</customfieldname>
                        <customfieldvalues>
                            <customfieldvalue>14369</customfieldvalue>
                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            </customfields>
    </item>
</channel>
</rss>