<!-- 
RSS generated by JIRA (9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66) at Wed Feb 07 21:35:44 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-75] Deserialization discriminators are too lazy</title>
                <link>https://jira.mongodb.org/browse/CSHARP-75</link>
                <project id="10041" key="CSHARP">C# Driver</project>
                    <description>&lt;p&gt;Long story short, this works:&lt;br/&gt;
                Foo ret = new Foo();&lt;br/&gt;
                Trace.TraceInformation(&quot;Doing stuff to &lt;/p&gt;
{0}
&lt;p&gt;.&quot;, ret.ToJson());&lt;br/&gt;
                ret = collection.FindOneAs&amp;lt;Event&amp;gt;(someQuery);&lt;br/&gt;
                return ret;&lt;/p&gt;

&lt;p&gt;Take away the ToJson() call it breaks because BsonClassMap.AutoMap() does not get called which causes BsonClassMap.LookupActualType() to fail. I am not sure how to fix. &lt;/p&gt;

&lt;p&gt;Let me know if you need a better description and I can provide one.&lt;/p&gt;</description>
                <environment></environment>
        <key id="13427">CSHARP-75</key>
            <summary>Deserialization discriminators are too lazy</summary>
                <type id="1" iconUrl="https://jira.mongodb.org/secure/viewavatar?size=xsmall&amp;avatarId=14703&amp;avatarType=issuetype">Bug</type>
                                            <priority id="2" iconUrl="https://jira.mongodb.org/images/icons/priorities/critical.svg">Critical - P2</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="zippy1981">Justin Dearing</reporter>
                        <labels>
                    </labels>
                <created>Tue, 19 Oct 2010 18:22:27 +0000</created>
                <updated>Wed, 19 Oct 2016 14:16:07 +0000</updated>
                            <resolved>Wed, 20 Oct 2010 04:25:55 +0000</resolved>
                                                                                        <votes>0</votes>
                                    <watches>0</watches>
                                                                                                                <comments>
                            <comment id="19394" author="rstam" created="Wed, 20 Oct 2010 14:56:20 +0000"  >&lt;p&gt;Or maybe even:&lt;/p&gt;

&lt;p&gt;BsonClassMap.LookupClassMap(typeof(Book));&lt;br/&gt;
BsonClassMap.LookupClassMap(typeof(Magazine)); &lt;/p&gt;

&lt;p&gt;If you&apos;re willing to make sure you only call them once you could use:&lt;/p&gt;

&lt;p&gt;BsonClassMap.RegisterClassMap&amp;lt;Book&amp;gt;();&lt;br/&gt;
BsonClassMap.RegisterClassMap&amp;lt;Magazine&amp;gt;();&lt;/p&gt;

&lt;p&gt;RegisterClassMap throws an exception if you try to register the same class more than once.&lt;/p&gt;

&lt;p&gt;Or just use the &lt;span class=&quot;error&quot;&gt;&amp;#91;BsonKnownType&amp;#93;&lt;/span&gt; attribute! &lt;img class=&quot;emoticon&quot; src=&quot;https://jira.mongodb.org/images/icons/emoticons/smile.png&quot; height=&quot;16&quot; width=&quot;16&quot; align=&quot;absmiddle&quot; alt=&quot;&quot; border=&quot;0&quot;/&gt;&lt;/p&gt;

&lt;p&gt;Good catch.&lt;/p&gt;</comment>
                            <comment id="19392" author="zippy1981" created="Wed, 20 Oct 2010 14:41:40 +0000"  >&lt;p&gt;A small amendment to Robert&apos;s comment. The correct syntax is:&lt;/p&gt;

&lt;p&gt;BsonClassMap.LookupClassMap&amp;lt;Book&amp;gt;(); &lt;br/&gt;
BsonClassMap.LookupClassMap&amp;lt;Magazine&amp;gt;(); &lt;/p&gt;</comment>
                            <comment id="19377" author="rstam" created="Wed, 20 Oct 2010 04:25:55 +0000"  >&lt;p&gt;This is the result of an attempt to deserialize an instance of a class that has not yet been mapped (auto or otherwise). The reason calling ToJson first worked is because as a side effect of calling ToJson the class was automapped. This is a common case when you are deserializing the base class of an inheritance hierarchy. The different .NET serializers have various ways of telling the serializer about the &quot;known types&quot; that will be deserialized. In our case, I&apos;ve added a BsonKnownTypeAttribute for this purpose. Here&apos;s a sample family of classes:&lt;/p&gt;

&lt;p&gt;    &lt;span class=&quot;error&quot;&gt;&amp;#91;BsonKnownType(typeof(Book))&amp;#93;&lt;/span&gt;&lt;br/&gt;
    &lt;span class=&quot;error&quot;&gt;&amp;#91;BsonKnownType(typeof(Magazine))&amp;#93;&lt;/span&gt;&lt;br/&gt;
    public class Product {&lt;br/&gt;
    }&lt;/p&gt;

&lt;p&gt;    public class Book : Product {&lt;br/&gt;
        &lt;span class=&quot;error&quot;&gt;&amp;#91;BsonElement(&amp;quot;author&amp;quot;)&amp;#93;&lt;/span&gt;&lt;br/&gt;
        public string Author &lt;/p&gt;
{ get; set; }&lt;br/&gt;
&lt;br/&gt;
        &lt;span class=&quot;error&quot;&gt;&amp;#91;BsonElement(&amp;quot;title&amp;quot;)&amp;#93;&lt;/span&gt;&lt;br/&gt;
        public string Title { get; set; }
&lt;p&gt;    }&lt;/p&gt;

&lt;p&gt;    public class Magazine : Product {&lt;br/&gt;
        &lt;span class=&quot;error&quot;&gt;&amp;#91;BsonElement(&amp;quot;name&amp;quot;)&amp;#93;&lt;/span&gt;&lt;br/&gt;
        public string Name &lt;/p&gt;
{ get; set; }&lt;br/&gt;
    }&lt;br/&gt;
&lt;br/&gt;
    public class PackingList {&lt;br/&gt;
        public IList&amp;lt;Product&amp;gt; Products { get; set; }
&lt;p&gt;    }&lt;/p&gt;

&lt;p&gt;If you don&apos;t want to or can&apos;t annotate your classes with these attributes another way to make these classes &quot;known&quot; to the serializer is to call:&lt;/p&gt;

&lt;p&gt;BsonSerializer.LookupClassMap&amp;lt;Book&amp;gt;();&lt;br/&gt;
BsonSerializer.LookupClassMap&amp;lt;Magazine&amp;gt;();&lt;/p&gt;

&lt;p&gt;We are ignoring the return values. We only care about the side effect that the class is automapped if necessary (i.e, &quot;known&quot; to the serializer).&lt;/p&gt;</comment>
                            <comment id="19354" author="zippy1981" created="Tue, 19 Oct 2010 19:00:03 +0000"  >&lt;p&gt;No that was a bad bad search and replace to &quot;sanatize&quot; my code&lt;/p&gt;

&lt;p&gt;                Foo ret = new Foo(); &lt;br/&gt;
                Trace.TraceInformation(&quot;Doing stuff to &lt;/p&gt;
{0}
&lt;p&gt;.&quot;, ret.ToJson()); &lt;br/&gt;
                ret = collection.FindOneAs&amp;lt;Foo&amp;gt;(someQuery); &lt;br/&gt;
                return ret; &lt;/p&gt;</comment>
                            <comment id="19351" author="rstam" created="Tue, 19 Oct 2010 18:51:27 +0000"  >&lt;p&gt;Is Event supposed to be a subclass of Foo?&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|hrh9u7:</customfieldvalue>

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