<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:38:36 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-1076] Comment on: &quot;mongodb-ecosystem/tutorial/serialize-documents-with-the-csharp-driver.txt&quot;</title>
                <link>https://jira.mongodb.org/browse/CSHARP-1076</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Hi&lt;br/&gt;
I was trying to get the &quot;Rename&quot; code working and I think I stumbled across a possible issue with the example. &lt;/p&gt;

&lt;p&gt;Steps:&lt;br/&gt;
1. Create Person class with Name and Age properties&lt;br/&gt;
2. Serialized an instance of Person to my MongoDb&lt;br/&gt;
3. Code returns collection of Person and displays to console.&lt;/p&gt;

&lt;p&gt;4. Changed Person class to Name and OldAge properties&lt;br/&gt;
5. Serialized an instance of Person to my MongoDb&lt;br/&gt;
6. When attempting to display collection to console, it excepts.&lt;/p&gt;

&lt;p&gt;Code:&lt;br/&gt;
public class Person : ISupportInitialize&lt;br/&gt;
{&lt;br/&gt;
    public ObjectId Id &lt;/p&gt;
{ get; set; }&lt;br/&gt;
    public string Name { get; set; }
&lt;p&gt;    public int OldAge&lt;/p&gt;
{ get; set; }&lt;br/&gt;
&lt;br/&gt;
    &lt;span class=&quot;error&quot;&gt;&amp;#91;BsonExtraElements&amp;#93;&lt;/span&gt;&lt;br/&gt;
    public IDictionary&amp;lt;string, object&amp;gt; ExtraElements { get; set; }

&lt;p&gt;    public void BeginInit()&lt;/p&gt;
    {
        //
    }

&lt;p&gt;    public void EndInit()&lt;br/&gt;
    {&lt;br/&gt;
        object ageValue;&lt;/p&gt;

&lt;p&gt;        if (!ExtraElements.TryGetValue(&quot;Alive&quot;, out ageValue))&lt;/p&gt;
        {
            return;
        }

&lt;p&gt;        var age = (int)ageValue;&lt;/p&gt;

&lt;p&gt;        ExtraElements.Remove(&quot;Age&quot;);&lt;/p&gt;

&lt;p&gt;        OldAge = age;&lt;br/&gt;
    }&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;Problem: When deserializing the second record, ExtraElements is null.&lt;/p&gt;

&lt;p&gt;My resolution: The only way that I could make that code work was to do either of the following:&lt;/p&gt;

&lt;p&gt;1. Add a constructor to new up ExtraElements&lt;/p&gt;

&lt;p&gt;public Person()&lt;br/&gt;
{&lt;br/&gt;
    ExtraElements = new Dictionary&amp;lt;string, object&amp;gt;();&lt;br/&gt;
}&lt;/p&gt;

&lt;p&gt;2. Check if ExtraElements is null&lt;/p&gt;

&lt;p&gt;if ((ExtraElements == null) || (!ExtraElements.TryGetValue(&quot;Age&quot;, out ageValue)))&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Reporter&lt;/b&gt;: Richard O&apos;Neil&lt;br/&gt;
&lt;b&gt;E-mail&lt;/b&gt;: &lt;span class=&quot;nobr&quot;&gt;&lt;a href=&quot;mailto:richard.oneil@garvin-allen.com&quot; class=&quot;external-link&quot; target=&quot;_blank&quot; rel=&quot;nofollow noopener&quot;&gt;richard.oneil@garvin-allen.com&lt;sup&gt;&lt;img class=&quot;rendericon&quot; src=&quot;https://jira.mongodb.org/images/icons/mail_small.gif&quot; height=&quot;12&quot; width=&quot;13&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/sup&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;</description>
                <environment>VS2013, C#, Win8.1, etc...&lt;br/&gt;
&lt;br/&gt;
*Location*: &lt;a href=&quot;http://docs.mongodb.org/ecosystem/tutorial/serialize-documents-with-the-csharp-driver/&quot;&gt;http://docs.mongodb.org/ecosystem/tutorial/serialize-documents-with-the-csharp-driver/&lt;/a&gt;&lt;br/&gt;
*User-Agent*: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36&lt;br/&gt;
*Referrer*: &lt;a href=&quot;http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-csharp-driver/&quot;&gt;http://docs.mongodb.org/ecosystem/tutorial/getting-started-with-csharp-driver/&lt;/a&gt;&lt;br/&gt;
*Screen Resolution*: 1680 x 1050&lt;br/&gt;
*repo*: docs-ecosystem&lt;br/&gt;
*source*: tutorial/serialize-documents-with-the-csharp-driver&lt;br/&gt;
</environment>
        <key id="141324">CSHARP-1076</key>
            <summary>Comment on: &quot;mongodb-ecosystem/tutorial/serialize-documents-with-the-csharp-driver.txt&quot;</summary>
                <type id="4" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14710&amp;avatarType=issuetype">Improvement</type>
                                            <priority id="1" iconUrl="https://jira.mongodb.org/images/icons/priorities/blocker.svg">Blocker - P1</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="-1">Unassigned</assignee>
                                    <reporter username="xgen-internal-docs">Docs Collector User</reporter>
                        <labels>
                            <label>collector-298ba4e7</label>
                    </labels>
                <created>Tue, 10 Jun 2014 15:15:18 +0000</created>
                <updated>Sat, 4 Apr 2015 22:30:30 +0000</updated>
                            <resolved>Sat, 4 Apr 2015 22:30:30 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>1</watches>
                                                                                                                        <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|hrzl5r:</customfieldvalue>

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