<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:46:35 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-3889] System.InvalidOperationException: &apos;An Array value cannot be written to the root level of a BSON document.&apos; when using MongoDB.Bson version 2.11.0 or higher</title>
                <link>https://jira.mongodb.org/browse/CSHARP-3889</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Running the code in the attached project results in an exception:&lt;/p&gt;

&lt;p&gt;System.InvalidOperationException: &apos;An Array value cannot be written to the root level of a BSON document.&apos;&lt;/p&gt;

&lt;p&gt;when using MongoDB.Bson version 2.11.0 or higher.&lt;/p&gt;

&lt;p&gt;The issue does not reproduce when using 2.10.4 or lower.&lt;/p&gt;

&lt;p&gt;It seems to be related to &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-2877&quot; title=&quot;Default BsonSerializationArgs sometimes has null NominalType&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-2877&quot;&gt;&lt;del&gt;CSHARP-2877&lt;/del&gt;&lt;/a&gt;.&lt;/p&gt;</description>
                <environment></environment>
        <key id="1890153">CSHARP-3889</key>
            <summary>System.InvalidOperationException: &apos;An Array value cannot be written to the root level of a BSON document.&apos; when using MongoDB.Bson version 2.11.0 or higher</summary>
                <type id="3" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14718&amp;avatarType=issuetype">Task</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="13202">Works as Designed</resolution>
                                        <assignee username="james.kovacs@mongodb.com">James Kovacs</assignee>
                                    <reporter username="johnjames.smith75@protonmail.com">John James Smith</reporter>
                        <labels>
                    </labels>
                <created>Tue, 5 Oct 2021 14:54:21 +0000</created>
                <updated>Fri, 27 Oct 2023 13:24:43 +0000</updated>
                            <resolved>Thu, 14 Oct 2021 20:09:23 +0000</resolved>
                                                                    <component>Serialization</component>
                                        <votes>0</votes>
                                    <watches>2</watches>
                                                                                                                <comments>
                            <comment id="4125046" author="xgen-internal-githook" created="Thu, 14 Oct 2021 20:05:53 +0000"  >&lt;p&gt;Author:&lt;/p&gt;
{&apos;name&apos;: &apos;James Kovacs&apos;, &apos;email&apos;: &apos;jkovacs@post.harvard.edu&apos;, &apos;username&apos;: &apos;JamesKovacs&apos;}
&lt;p&gt;Message: &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-2877&quot; title=&quot;Default BsonSerializationArgs sometimes has null NominalType&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-2877&quot;&gt;&lt;del&gt;CSHARP-2877&lt;/del&gt;&lt;/a&gt; / &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-3889&quot; title=&quot;System.InvalidOperationException: &amp;#39;An Array value cannot be written to the root level of a BSON document.&amp;#39; when using MongoDB.Bson version 2.11.0 or higher&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-3889&quot;&gt;&lt;del&gt;CSHARP-3889&lt;/del&gt;&lt;/a&gt;: Added upgrade warning for 2.11.0+ as BsonSerializer.Serialize no longer allows arrays at the root of a BSON document. (#645)&lt;br/&gt;
Branch: master&lt;br/&gt;
&lt;a href=&quot;https://github.com/mongodb/mongo-csharp-driver/commit/80c7c8e10b81ae942d73ebf38317244706de124b&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;https://github.com/mongodb/mongo-csharp-driver/commit/80c7c8e10b81ae942d73ebf38317244706de124b&lt;/a&gt;&lt;/p&gt;</comment>
                            <comment id="4104631" author="JIRAUSER1262740" created="Wed, 6 Oct 2021 09:51:20 +0000"  >&lt;p&gt;Thank you for the response. I understand this is the expected behavior and this Jira can be closed, however, maybe this should be noted as a breaking change when upgrading from an older version, as this can result in an unexpected runtime exception.&lt;/p&gt;</comment>
                            <comment id="4103166" author="james.kovacs" created="Tue, 5 Oct 2021 18:18:39 +0000"  >&lt;p&gt;Hi, &lt;a href=&quot;https://jira.mongodb.org/secure/ViewProfile.jspa?name=johnjames.smith75%40protonmail.com&quot; class=&quot;user-hover&quot; rel=&quot;johnjames.smith75@protonmail.com&quot;&gt;johnjames.smith75@protonmail.com&lt;/a&gt;,&lt;/p&gt;

&lt;p&gt;Thank you for reporting this issue and providing a reproduction. We have confirmed that it was introduced in 2.11.0 by &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-2877&quot; title=&quot;Default BsonSerializationArgs sometimes has null NominalType&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-2877&quot;&gt;&lt;del&gt;CSHARP-2877&lt;/del&gt;&lt;/a&gt;. It is however correct behaviour according to the &lt;a href=&quot;https://bsonspec.org/spec.html&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;BSON Spec&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A BSON document consists of a list of field name / field value pairs. Arrays are serialized as &quot;\x04&quot; (array type identifier), the name of the field, and then integer keys (as strings) with array values. For example, consider the following document:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;{ &quot;someArray&quot; : [ &quot;red&quot;, &quot;blue&quot; ] } &lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;This would be represented in BSON as:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;{ (type \x04) &quot;someArray&quot; : { &quot;0&quot; : &quot;red&quot;, &quot;1&quot; : &quot;blue&quot; } }&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;The serialized value of the array on its own is ambiguous because it doesn&apos;t have a BSON type associated with it. The root of a BSON document must be a list of name/value pairs and cannot be a freestanding array.&lt;/p&gt;

&lt;p&gt;Hopefully this explains the change in behaviour introduced by &lt;a href=&quot;https://jira.mongodb.org/browse/CSHARP-2877&quot; title=&quot;Default BsonSerializationArgs sometimes has null NominalType&quot; class=&quot;issue-link&quot; data-issue-key=&quot;CSHARP-2877&quot;&gt;&lt;del&gt;CSHARP-2877&lt;/del&gt;&lt;/a&gt; in 2.11.0. A common practice is to wrap the value as follows:&lt;/p&gt;

&lt;p/&gt;
&lt;div id=&quot;syntaxplugin&quot; class=&quot;syntaxplugin&quot; style=&quot;border: 1px dashed #bbb; border-radius: 5px !important; overflow: auto; max-height: 30em;&quot;&gt;
&lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot; width=&quot;100%&quot; style=&quot;font-size: 1em; line-height: 1.4em !important; font-weight: normal; font-style: normal; color: black;&quot;&gt;
		&lt;tbody &gt;
				&lt;tr id=&quot;syntaxplugin_code_and_gutter&quot;&gt;
						&lt;td  style=&quot; line-height: 1.4em !important; padding: 0em; vertical-align: top;&quot;&gt;
					&lt;pre style=&quot;font-size: 1em; margin: 0 10px;  margin-top: 10px;   margin-bottom: 10px;  width: auto; padding: 0;&quot;&gt;&lt;span style=&quot;color: black; font-family: &apos;Consolas&apos;, &apos;Bitstream Vera Sans Mono&apos;, &apos;Courier New&apos;, Courier, monospace !important;&quot;&gt;{ &quot;_v&quot; : ARRAY }&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&gt;
			&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p/&gt;

&lt;p&gt;We use this technique internally in the driver when the return value is an array, integer, or other simple data type.&lt;/p&gt;

&lt;p&gt;Please let us know if you have any additional questions. If not, we will close this as &quot;works as designed&quot;.&lt;/p&gt;

&lt;p&gt;Sincerely,&lt;br/&gt;
James&lt;/p&gt;</comment>
                    </comments>
                <issuelinks>
                            <issuelinktype id="10012">
                    <name>Related</name>
                                            <outwardlinks description="related to">
                                        <issuelink>
            <issuekey id="1056504">CSHARP-2877</issuekey>
        </issuelink>
                            </outwardlinks>
                                                        </issuelinktype>
                    </issuelinks>
                <attachments>
                            <attachment id="338829" name="BsonTest.zip" size="4093" author="johnjames.smith75@protonmail.com" created="Tue, 5 Oct 2021 14:51:39 +0000"/>
                    </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|hzo2an:</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>