<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:36:46 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-417] BsonArray doesn&apos;t support null values</title>
                <link>https://jira.mongodb.org/browse/CSHARP-417</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Looking at the source code for BsonArray.cs, there are numerous places where null values in the array will cause a crash.&lt;/p&gt;


&lt;p&gt;line 676:&lt;br/&gt;
clone.Add(value.DeepClone());&lt;/p&gt;

&lt;p&gt;line 722:&lt;br/&gt;
hash = 37 * hash + value.GetHashCode();&lt;/p&gt;

&lt;p&gt;line 818:&lt;br/&gt;
sb.Append(_values&lt;span class=&quot;error&quot;&gt;&amp;#91;i&amp;#93;&lt;/span&gt;.ToString());&lt;/p&gt;

&lt;p&gt;line 833:&lt;br/&gt;
_values&lt;span class=&quot;error&quot;&gt;&amp;#91;i&amp;#93;&lt;/span&gt;.WriteTo(bsonWriter);&lt;/p&gt;

&lt;p&gt;..and I&apos;m sure there are other places!&lt;/p&gt;

&lt;p&gt;To reproduce: deserialize some JSON with a null in an array, then try adding to Mongo with the driver.&lt;/p&gt;

&lt;p&gt;My understanding is that null values are valid JSON and valid BSON, so should be supported by Mongo and the C# driver.&lt;/p&gt;

&lt;p&gt;I&apos;m happy to work on this - but am too busy this week.&lt;/p&gt;

&lt;p&gt;Thanks,&lt;br/&gt;
Ben&lt;/p&gt;

</description>
                <environment></environment>
        <key id="34774">CSHARP-417</key>
            <summary>BsonArray doesn&apos;t support null values</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="benblamey">Ben Blamey</reporter>
                        <labels>
                            <label>crash</label>
                    </labels>
                <created>Tue, 27 Mar 2012 12:19:40 +0000</created>
                <updated>Thu, 2 Apr 2015 18:28:21 +0000</updated>
                            <resolved>Tue, 10 Apr 2012 17:42:16 +0000</resolved>
                                    <version>1.4</version>
                                    <fixVersion>1.4.1</fixVersion>
                                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                <comments>
                            <comment id="108370" author="rstam" created="Tue, 10 Apr 2012 17:42:16 +0000"  >&lt;p&gt;When mapping from .NET data types to BsonDocument object model null is mapped to BsonNull.Value. When creating BsonValues using functional construction null is ignored.&lt;/p&gt;</comment>
                            <comment id="104254" author="benblamey" created="Wed, 28 Mar 2012 11:14:27 +0000"  >&lt;p&gt;Cracking. &lt;/p&gt;

&lt;p&gt;My scenario is pretty typical: I want to store a JsonObject (from SimpleJson) in a Mongo database - thats the object I get back from a different API. That object is cast to an IDictionary&amp;lt;,&amp;gt; - so I want to faithfully preserve the underlying original JSON document (which I don&apos;t have). It would suit me best (and be most logical) if construction from IDictionary&amp;lt;,&amp;gt; follow JSON principles of keeping nulls.&lt;/p&gt;

&lt;p&gt;Thanks.&lt;/p&gt;</comment>
                            <comment id="104033" author="rstam" created="Tue, 27 Mar 2012 16:59:57 +0000"  >&lt;p&gt;Thanks for the test case.&lt;/p&gt;

&lt;p&gt;The fix should probably be in the caller to BsonValue.Create, but I&apos;ll evaluate that more carefully when I get to this.&lt;/p&gt;

&lt;p&gt;The reason it&apos;s not clear cut is that the BsonDocument object model follows the functional construction pattern used by XDocument, where null is used to mean skip this item.&lt;/p&gt;

&lt;p&gt;In any case, a NullReferenceException is definitely not the right behavior!&lt;/p&gt;</comment>
                            <comment id="103989" author="benblamey" created="Tue, 27 Mar 2012 15:24:06 +0000"  >&lt;p&gt;Hi Robert - Sorry for jumping to conclusions - should have RTFM!!&lt;/p&gt;

&lt;p&gt;Anyway, I do actually get an exception with nulls.....I&apos;ve made a failing test case:&lt;/p&gt;

&lt;p&gt;var dict1 = new Dictionary&amp;lt;string, object&amp;gt;() { { &quot;foo&quot;, new object[] &lt;/p&gt;
{ null }
&lt;p&gt; } };&lt;br/&gt;
var document1 = new UpdateDocument(dict1);&lt;br/&gt;
document1.ToBson();&lt;/p&gt;

&lt;p&gt;Looks to me like the prob lem is BsonValue.cs : public static BsonValue Create(object value)&lt;/p&gt;

&lt;p&gt;            if (value == null)&lt;/p&gt;
            {
                return null;  // Should be a BsonNull?
            }

&lt;p&gt;..Which presumably is how the null ends up inside the document&lt;/p&gt;

&lt;p&gt;Here is the stack trace:&lt;/p&gt;

&lt;p&gt;System.NullReferenceException was unhandled&lt;br/&gt;
  Message=Object reference not set to an instance of an object.&lt;br/&gt;
  Source=MongoDB.Bson&lt;br/&gt;
  StackTrace:&lt;br/&gt;
       at MongoDB.Bson.BsonArray.WriteTo(BsonWriter bsonWriter) in D:\code\mongo-csharp-driver\Bson\ObjectModel\BsonArray.cs:line 833&lt;br/&gt;
       at MongoDB.Bson.BsonValue.WriteTo(BsonWriter bsonWriter) in D:\code\mongo-csharp-driver\Bson\ObjectModel\BsonValue.cs:line 1230&lt;br/&gt;
       at MongoDB.Bson.BsonElement.WriteTo(BsonWriter bsonWriter) in D:\code\mongo-csharp-driver\Bson\ObjectModel\BsonElement.cs:line 276&lt;br/&gt;
       at MongoDB.Bson.BsonDocument.Serialize(BsonWriter bsonWriter, Type nominalType, IBsonSerializationOptions options) in D:\code\mongo-csharp-driver\Bson\ObjectModel\BsonDocument.cs:line 1041&lt;br/&gt;
       at MongoDB.Bson.Serialization.BsonSerializer.Serialize(BsonWriter bsonWriter, Type nominalType, Object value, IBsonSerializationOptions options) in D:\code\mongo-csharp-driver\Bson\Serialization\BsonSerializer.cs:line 561&lt;br/&gt;
       at MongoDB.Bson.BsonExtensionMethods.ToBson(Object obj, Type nominalType, IBsonSerializationOptions options, BsonBinaryWriterSettings settings) in D:\code\mongo-csharp-driver\Bson\BsonExtensionMethods.cs:line 124&lt;br/&gt;
       at MongoDB.Bson.BsonExtensionMethods.ToBson(Object obj, Type nominalType, BsonBinaryWriterSettings settings) in D:\code\mongo-csharp-driver\Bson\BsonExtensionMethods.cs:line 139&lt;br/&gt;
       at MongoDB.Bson.BsonExtensionMethods.ToBson(Object obj, Type nominalType) in D:\code\mongo-csharp-driver\Bson\BsonExtensionMethods.cs:line 91&lt;br/&gt;
       at MongoDB.Bson.BsonExtensionMethods.ToBson&lt;span class=&quot;error&quot;&gt;&amp;#91;TNominalType&amp;#93;&lt;/span&gt;(TNominalType obj) in D:\code\mongo-csharp-driver\Bson\BsonExtensionMethods.cs:line 40&lt;br/&gt;
.. my code..&lt;br/&gt;
  InnerException: &lt;br/&gt;
(none)&lt;/p&gt;</comment>
                            <comment id="103958" author="rstam" created="Tue, 27 Mar 2012 14:05:44 +0000"  >&lt;p&gt;BSON/JSON nulls are supported by the C# driver and are represented in the BsonDocument object model by the BsonNull.Value singleton (not with a C# null).&lt;/p&gt;

&lt;p&gt;For example, the following code works:&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;   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;var json = &quot;{ x : 1, a : [ 1, null ] }&quot;;&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&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;   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;var document = BsonDocument.Parse(json);&lt;/span&gt;&lt;/pre&gt;
			&lt;/td&gt;
		&lt;/tr&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-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;Console.WriteLine(document.ToJson());&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;and outputs&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;x&quot; : 1, &quot;a&quot; : [1, null] }&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;Have you actually gotten a NullReferenceException from any of the above lines?&lt;/p&gt;</comment>
                            <comment id="103934" author="benblamey" created="Tue, 27 Mar 2012 12:24:14 +0000"  >&lt;p&gt;I&apos;m looking at the code at this commit:&lt;br/&gt;
8c7909d4a24a5388a67174a43c3773b142602e9b BUMP 1.4.0.4468&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|hrh7uv:</customfieldvalue>

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