<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:37:24 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-635] Postpone creation of serializers until they are first needed</title>
                <link>https://jira.mongodb.org/browse/CSHARP-635</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;In March 2012, &lt;a href=&quot;https://github.com/g0t4/mongo-csharp-driver/commit/1ad28750b052a8c6f789d39c6d522798c0aafc46&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/g0t4/mongo-csharp-driver/commit/1ad28750b052a8c6f789d39c6d522798c0aafc46&lt;/a&gt;, the driver was updated to clone &amp;amp; freeze default options in BsonBaseSerializer&apos;s constructor.  As a result, any calls to several static constructors in the API will trigger this and freeze the default options at that point in time for DictionarySerializationOptions and DateTimeSerializationOptions. It&apos;s very easy to accidentally trigger and in some cases hard to avoid when re-using modules that depend on mongodb that have their own initialization that might trigger it as well.  I have a patch request coming from GitHub.&lt;/p&gt;

&lt;p&gt;If clone &amp;amp; freeze is left, this should be reflected with exceptions in the defaults API (DateTimeSerializationOptions.Defaults), but even doing that would cause issues when modules trigger the Clone &amp;amp; Freeze, so I would suggest Freezing be a feature the consumer can request if desired and not forced on them via the driver and Clone should be removed.&lt;/p&gt;

&lt;p&gt;IMO, the best fix would be to refactor the configuration of serialization (primarily BsonSerializer) to be contextual and not static, this way different modules can operate in the same process and not stomp on each other&apos;s configuration.  This could be passed into a new MongoDatabase and forwarded to MongoCollection instances.&lt;/p&gt;

&lt;p&gt;&lt;span class=&quot;error&quot;&gt;&amp;#91;Edited by Robert Stam&amp;#93;&lt;/span&gt;:&lt;/p&gt;

&lt;p&gt;See the comment added 11/29 describing the actual change made to address setting default options for serializers. The summary of the issue has also been edited to reflect that.&lt;/p&gt;

&lt;p&gt;To summarize the changes:&lt;/p&gt;

&lt;ul class=&quot;alternate&quot; type=&quot;square&quot;&gt;
	&lt;li&gt;we are deprecating almost all the static Instance properties&lt;/li&gt;
	&lt;li&gt;we are deprecating the XyzSerializationOptions.Defaults properties&lt;/li&gt;
	&lt;li&gt;the recommended way to set the defaults is now to create a serializer with the desired defaults and register it&lt;/li&gt;
	&lt;li&gt;the default serialization provider now creates serializers as late as possible so if you do set the deprecated Defaults properties they will be used (but they will be removed in 2.0)&lt;/li&gt;
&lt;/ul&gt;
</description>
                <environment>Windows 8</environment>
        <key id="57515">CSHARP-635</key>
            <summary>Postpone creation of serializers until they are first needed</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="4" iconUrl="https://jira.mongodb.org/images/icons/priorities/minor.svg">Minor - P4</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="wes.mcclure@gmail.com">Wesley McClure</reporter>
                        <labels>
                            <label>c#</label>
                            <label>driver</label>
                    </labels>
                <created>Mon, 26 Nov 2012 20:24:46 +0000</created>
                <updated>Thu, 20 Mar 2014 14:36:06 +0000</updated>
                            <resolved>Tue, 1 Jan 2013 00:02:13 +0000</resolved>
                                    <version>1.7</version>
                                    <fixVersion>1.8</fixVersion>
                                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="228117" author="auto" created="Tue, 1 Jan 2013 00:01:35 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{u&apos;date&apos;: u&apos;2012-12-31T23:59:11Z&apos;, u&apos;email&apos;: u&apos;robert@10gen.com&apos;, u&apos;name&apos;: u&apos;rstam&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-635&quot; title=&quot;Postpone creation of serializers until they are first needed&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-635&quot;&gt;&lt;del&gt;CSHARP-635&lt;/del&gt;&lt;/a&gt;: Postpone creation of serializers until they are first needed.&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/5dabdce56d47b47dcd95edd738a4ea8fc78de4e4&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/5dabdce56d47b47dcd95edd738a4ea8fc78de4e4&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="228115" author="rstam" created="Mon, 31 Dec 2012 23:58:33 +0000"  >&lt;p&gt;Changed the description of the JIRA issue to match what we are actually changing to address this issue.&lt;/p&gt;</comment>
                            <comment id="228004" author="rstam" created="Mon, 31 Dec 2012 19:54:27 +0000"  >&lt;p&gt;Linked to a new JIRA proposing possible support for multiple serialization contexts.&lt;/p&gt;</comment>
                            <comment id="202850" author="rstam" created="Fri, 30 Nov 2012 04:21:54 +0000"  >&lt;p&gt;I don&apos;t think removing Clone and Freeze is the proper solution. It is important to freeze the default serialization options when the serializer is created because we want serialization to be stable. We don&apos;t want you to be able to modify the behavior of a serializer after it has been created and registered.&lt;/p&gt;

&lt;p&gt;I think the real problem is that the static BsonDateTimeSerializer Instance is being created too early (and therefore picking up the value of DateTimeSerializationOptions.Defaults before you have had a chance to set it). I think the proper solution is to get rid of the static Instance property in BsonDateTimeSerializer (the one that is being created too early) and to change the __serializers dictionary in BsonDefaultSerializationProvider to be a mapping from data types to serializer types (instead of to serializer instances) and to postpone creating the serializer instance until it is first needed, giving you ample chance to set the DateTimeSerializationOptions Defaults first.&lt;/p&gt;

&lt;p&gt;It would probably also be a good idea to deprecate the Defaults property of DateTimeSerializationOptions, and instead provide a new constructor of DateTimeSerializer that lets you pass in the desired default options. Then instead of setting DateTimeSerializationOptions.Defaults you would create and register an instance of DateTimeSerializer with the desired defaults.&lt;/p&gt;</comment>
                            <comment id="202785" author="rstam" created="Fri, 30 Nov 2012 02:34:50 +0000"  >&lt;p&gt;Thanks for the sample code. It&apos;s very helpful to have an actual use case to look at.&lt;/p&gt;</comment>
                            <comment id="202780" author="wes.mcclure@gmail.com" created="Fri, 30 Nov 2012 02:30:32 +0000"  >&lt;p&gt;Yes and no, I don&apos;t think it&apos;s necessary at any point, but:&lt;/p&gt;

&lt;p&gt;This code works:&lt;br/&gt;
			DateTimeSerializationOptions.Defaults = new DateTimeSerializationOptions(DateTimeKind.Local);&lt;br/&gt;
			BsonSerializer.UseNullIdChecker = true;&lt;/p&gt;

&lt;p&gt;However if I simply flip the order around, it will no longer accept my defaults because the static call to BsonSerializer reaches all the way to clone &amp;amp; freeze in the datetime serializer:&lt;br/&gt;
			BsonSerializer.UseNullIdChecker = true;&lt;br/&gt;
			DateTimeSerializationOptions.Defaults = new DateTimeSerializationOptions(DateTimeKind.Local);&lt;/p&gt;

&lt;p&gt;This is not easy to figure out without looking at driver code and is breaking several of our apps that were initially built on the 1.3 drivers.&lt;/p&gt;

&lt;p&gt;With that said, I&apos;d prefer to have serialization contextual, I think that&apos;s the better approach to clone &amp;amp; freeze, I&apos;d be willing to help make those changes happen but the bigger problem is the fact that it might not be possible without breaking changes to the API surface.&lt;/p&gt;</comment>
                            <comment id="202584" author="rstam" created="Thu, 29 Nov 2012 22:09:29 +0000"  >&lt;p&gt;I&apos;m not entirely sure what your point is. Are you saying that you would like to be able to change the value of DateTimeSerializationOptions.Defaults at any time during the execution of your program and have the BsonDateTimeSerializer start using the new value from then on?&lt;/p&gt;

&lt;p&gt;We have talked about (and prototyped) having multiple serialization configs (instead of a single global one like we do know), but it&apos;s a pretty big change.&lt;/p&gt;</comment>
                            <comment id="199423" author="wes.mcclure@gmail.com" created="Mon, 26 Nov 2012 20:26:32 +0000"  >&lt;p&gt;&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/pull/141&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/pull/141&lt;/a&gt;&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="60651">CSHARP-655</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                    </attachments>
                <subtasks>
                    </subtasks>
                <customfields>
                                                                                                                                                                                                                        <customfield id="customfield_10011" key="com.atlassian.jira.plugin.system.customfieldtypes:radiobuttons">
                        <customfieldname>Backwards Compatibility</customfieldname>
                        <customfieldvalues>
                                <customfieldvalue key="10012"><![CDATA[Major Change]]></customfieldvalue>

                        </customfieldvalues>
                    </customfield>
                                                                                                                                                                                <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|hrkrpr:</customfieldvalue>

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