<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:47:51 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-4310] ISupportInitialize methods not called when class derives from Dictionary</title>
                <link>https://jira.mongodb.org/browse/CSHARP-4310</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;h4&gt;&lt;a name=&quot;Summary&quot;&gt;&lt;/a&gt;Summary&lt;/h4&gt;

&lt;p&gt;ISupportInitialize methods are not called when document class derives from Dictionary&amp;lt;string, object&amp;gt;.&lt;/p&gt;
&lt;h4&gt;&lt;a name=&quot;Pleaseprovidetheversionofthedriver.Ifapplicable%2CpleaseprovidetheMongoDBserverversionandtopology%28standalone%2Creplicaset%2Corshardedcluster%29.&quot;&gt;&lt;/a&gt;Please provide the version of the driver. If applicable, please provide the MongoDB server version and topology (standalone, replica set, or sharded cluster).&lt;/h4&gt;

&lt;p&gt;MongoDB.Driver 2.17.1&lt;/p&gt;
&lt;h4&gt;&lt;a name=&quot;HowtoReproduce&quot;&gt;&lt;/a&gt;How to Reproduce&lt;/h4&gt;

&lt;p&gt;Consider following document class:&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;public class MyType: Dictionary&amp;lt;string, object&amp;gt;, ISupportInitialize&lt;/tt&gt;&lt;br/&gt;
{{{}}&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &lt;span class=&quot;error&quot;&gt;&amp;#91;BsonId&amp;#93;&lt;/span&gt;&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; public string Id&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; {&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; get =&amp;gt; (string)this&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;id&amp;quot;&amp;#93;&lt;/span&gt;;&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; set =&amp;gt; this&lt;span class=&quot;error&quot;&gt;&amp;#91;&amp;quot;id&amp;quot;&amp;#93;&lt;/span&gt; = value;&lt;/tt&gt;&lt;br/&gt;
{{&#160; &#160; }}}&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;&#160; &#160; public void BeginInit()&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; {&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; // this never gets executed:&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; throw new NotImplementedException();&lt;/tt&gt;&lt;br/&gt;
{{&#160; &#160; }}}&lt;/p&gt;

&lt;p&gt;&lt;tt&gt;&#160; &#160; public void EndInit()&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; {&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; // this never gets executed:&lt;/tt&gt;&lt;br/&gt;
&lt;tt&gt;&#160; &#160; &#160; &#160; throw new NotImplementedException();&lt;/tt&gt;&lt;br/&gt;
{{&#160; &#160; }}}&lt;br/&gt;
&lt;tt&gt;}&lt;/tt&gt;&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;

&lt;p&gt;Now enumerating the collection deserializes the items correctly as Dictionary objects, but BeginInit() and EndInit() never get called.&lt;/p&gt;

&lt;p&gt;&#160;&lt;/p&gt;
&lt;h4&gt;&lt;a name=&quot;AdditionalBackground&quot;&gt;&lt;/a&gt;Additional Background&lt;/h4&gt;

&lt;p&gt;&lt;em&gt;Please provide any additional background information that may be helpful in diagnosing the bug.&lt;/em&gt;&lt;/p&gt;</description>
                <environment></environment>
        <key id="2130790">CSHARP-4310</key>
            <summary>ISupportInitialize methods not called when class derives from Dictionary</summary>
                <type id="2" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14711&amp;avatarType=issuetype">New Feature</type>
                                            <priority id="10300" iconUrl="https://jira.mongodb.org/images/icons/priorities/medium.svg">Unknown</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="13203">Gone away</resolution>
                                        <assignee username="james.kovacs@mongodb.com">James Kovacs</assignee>
                                    <reporter username="mywyb2@gmail.com">Mo B.</reporter>
                        <labels>
                    </labels>
                <created>Wed, 7 Sep 2022 14:16:24 +0000</created>
                <updated>Fri, 27 Oct 2023 19:56:02 +0000</updated>
                            <resolved>Tue, 27 Sep 2022 12:00:38 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>4</watches>
                                                                                                                <comments>
                            <comment id="4857981" author="dbeng-pm-bot" created="Tue, 27 Sep 2022 12:00:40 +0000"  >&lt;p&gt;There hasn&apos;t been any recent activity on this ticket, so we&apos;re resolving it. Thanks for reaching out! Please feel free to comment on this if you&apos;re able to provide more information.&lt;/p&gt;</comment>
                            <comment id="4820708" author="james.kovacs" created="Mon, 12 Sep 2022 21:07:48 +0000"  >&lt;p&gt;Hi, Mo,&lt;/p&gt;

&lt;p&gt;I wanted to follow up further on Boris&apos; comments. The &lt;tt&gt;CollectionsSerializationProvider&lt;/tt&gt; and related classes are intended to allow you to use custom collection types with your POCOs. They are not intended to be POCOs themselves.&lt;/p&gt;

&lt;p&gt;Typically a POCO would be a class with properties that is initialized with the BSON data read from MongoDB. If you have additional optional properties, you would mark a property as &lt;tt&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;BsonExtraElements&amp;#93;&lt;/span&gt;&lt;/tt&gt;, which could be a &lt;tt&gt;BsonDocument&lt;/tt&gt; or &lt;tt&gt;IDictionary&amp;lt;string, object&amp;gt;&lt;/tt&gt; and it would contain any fields not mapped to explicit properties.&lt;/p&gt;

&lt;p&gt;You can always take full control of serialization/deserialization by implementing &lt;tt&gt;IBsonSerializer&amp;lt;T&amp;gt;&lt;/tt&gt; yourself. There are various base classes that implement &lt;tt&gt;IBsonSerializer&amp;lt;T&amp;gt;&lt;/tt&gt; that will handle much of the boilerplate code required. For example, see &lt;tt&gt;SerializerBase&amp;lt;T&amp;gt;&lt;/tt&gt;. If all your classes are essentially a property bag with strongly-typed accessor properties, you could write and register your own serialization provider that instantiates the desired &lt;tt&gt;IBsonSerializer&amp;lt;T&amp;gt;&lt;/tt&gt; instances.&lt;/p&gt;

&lt;p&gt;We do not recommend structuring your POCOs as strongly-typed property bags due to the casting overhead on every property access. Our recommended approach is to use strongly-typed properties mapped via &lt;tt&gt;BsonClassMap&amp;lt;T&amp;gt;&lt;/tt&gt; or BSON attributes. You can further customize using creator maps, &lt;tt&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;BsonExtraElements&amp;#93;&lt;/span&gt;&lt;/tt&gt;, and similar constructs.&lt;/p&gt;

&lt;p&gt;Please let us know if you have any additional questions.&lt;/p&gt;

&lt;p&gt;Sincerely,&lt;br/&gt;
James&lt;/p&gt;</comment>
                            <comment id="4815497" author="JIRAUSER1257742" created="Fri, 9 Sep 2022 19:26:50 +0000"  >&lt;p&gt;Thanks &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=mywyb2%40gmail.com&quot; class=&quot;user-hover&quot; rel=&quot;mywyb2@gmail.com&quot;&gt;mywyb2@gmail.com&lt;/a&gt; for reporting this behaviour.&lt;/p&gt;

&lt;p&gt;By default DictionaryInterfaceImplementerSerializer serializer is used for classes implementing IDictionary interface.&lt;br/&gt;
This serializer does not &#160;support ISupportInitialize functionality.&lt;br/&gt;
As a workaround, simple custom serializer can be implemented for supporting ISupportInitialize in dictionary based types.&lt;/p&gt;

&lt;p&gt;We will be investigating this behaviour further, please follow this ticket for any updates.&lt;/p&gt;</comment>
                            <comment id="4808139" author="JIRAUSER1271026" created="Wed, 7 Sep 2022 14:31:47 +0000"  >&lt;p&gt;Forgot to mention that this is in .NET 6.&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|i0ryn4:</customfieldvalue>

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